微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

基于另一个变量的 XSLT 元素选择

如何解决基于另一个变量的 XSLT 元素选择

XSLT 新手,我正在尝试使用以下 xsl 文件,我想在其中选择基于同一 XSL 中的另一个变量的特定代码。使用 Saxon-He-10.5 版本的 jar。有人可以帮我完成这个 xsl 转换吗?我想在 output.xml 中打印所选代码标题

<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xpath-default-namespace="http://test.org/test"
  xmlns:fn="http://www.w3.org/2005/xpath-functions" 
  xmlns:lookup="http://lookup.data"
  exclude-result-prefixes="fn lookup xsl xsi">

<xsl:variable name="key1" select="&quot;status1&quot;"/>
  <xsl:output omit-xml-declaration="yes" method="xml"/>
  <xsl:variable name="header">
    <sections>
      <code key="status1" code="123" title="STATUS1"/>
      <code key="status2" code="456" title="STATUS2"/>  
    </sections>
  </xsl:variable>

  <xsl:variable name="data" select="$header/sections/code[@key=&quot;status1&quot;]" />
  <xsl:variable name="data1" select="$header/sections/code[@key=$key1]" />
  
  <xsl:template match="/">
        :<xsl:value-of select="$header" />:
        :<xsl:value-of select="$data" />:
        :<xsl:value-of select="$data/@title" />:
        :<xsl:value-of select="$data1/@title" />:
  </xsl:template>
     
</xsl:transform>

尝试使用命令提示符进行转换,如下所示:

java -cp saxon-he-10.5.jar net.sf.saxon.Transform Response.xml test.xsl > output.xml

解决方法

设置 @JsName("default") 会使您的代码失败。如果您确实需要您拥有的全局声明,则需要在本地覆盖它,如 xpath-default-namespace

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。