我正在研究如何使用单个XSLT根据条件(例如
)转换为不同的XML根元素<A> if A/a = true, then output ----> <B><b>something</b></B>
<a>true</a> --XSLT-->
</A> otherwise output ----> <C><c>something</c></C>
不确定如何去做,如果能做到的话。快速搜索但没有找到任何相关资源。
我可以在Java / xslt中实现相同的逻辑,就像有两个独立的xslt一样,并且有一个java程序检查输入xml,并根据输入值,使用一个或另一个xslt进行转换。我试图在xslt中做同样的事情,如果可能的话。
非常感谢任何帮助!
提前致谢!
答案 0 :(得分:0)
好像你只想写出表达你所拥有标准的不同模板(我为a
元素编制了样本值):
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="A[a = 'foo']">
<B>
<b>
<xsl:value-of select="a"/>
</b>
</B>
</xsl:template>
<xsl:template match="A[a = 'bar']">
<C>
<c>
<xsl:value-of select="a"/>
</c>
</C>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/3NzcBt8/和https://xsltfiddle.liberty-development.net/3NzcBt8/1有例子。