基于另一个变量的XSLT元素选择 [英] XSLT element selection based on another variable
本文介绍了基于另一个变量的XSLT元素选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<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
推荐答案
设置xpath-default-namespace
会导致代码失败。如果您确实需要GLOBAL声明,则需要在本地覆盖它,如<xsl:variable name="data" select="$header/sections/code[@key="status1"]" xpath-default-namespace=""/>
所示。
这篇关于基于另一个变量的XSLT元素选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文