问题描述
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=""status1""/>
<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="status1"]" />
<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
。