如果我要使用xslt在下面的xml中插入一段文本,条件语句会是什么样子?
<items xmlns="http://mynamespace.com/definition">
<item>
<number id="1"/>
</item>
<item>
<number id="2"/>
</item>
<!-- insert the below text -->
<reference>
<refNo id="a"/>
<refNo id="b"/>
</reference>
<!-- end insert -->
</items>
Run Code Online (Sandbox Code Playgroud)
这就是我的xsl目前的样子(条件错误......):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://mynamespace.com/definition"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="addRef">
<reference>
<refNo id="a"/>
<refNo id="b"/>
</reference>
</xsl:param>
<xsl:template match="node()|@*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- here is where the condition got stuck... -->
<xsl:template match="/items[namespace-url()=*]/item[position()=last()]">
<xsl:call-template name="identity"/>
<xsl:copy-of select="$addRef"/>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
我想在最底层之后添加引用部分,但我不知道如何绕过匹配具有(显式)命名空间的元素.
谢谢.
xslt ×1