简化示例:
<xsl:template name="helper">
<xsl:attribute name="myattr">first calculated value</xsl:attribute>
</xsl:template>
<xsl:template match="/>
<myelem>
<xsl:call-template name="helper" />
<xsl:attribute name="myattr">second calculated value</xsl:attribute>
</myelem>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
有没有办法让第二个将第二个计算值附加到同一个值myattr结果节点中属性?
我已经看到如果目标属性在源xml中,可以使用属性值模板,但是我可以以某种方式引用我之前附加到结果节点的属性的值吗?
提前致谢!
在XSLT样式表中,如何删除<xsl:attribute>标记内的前导和尾随空格?
例如,以下样式表:
<xsl:template match="/">
<xsl:element name="myelement">
<xsl:attribute name="myattribute">
attribute value
</xsl:attribute>
</xsl:element>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
输出:
<myelement myattribute=" attribute value "/>
Run Code Online (Sandbox Code Playgroud)
虽然我希望它输出:
<myelement myattribute="attribute value"/>
Run Code Online (Sandbox Code Playgroud)
除了将<xsl:attribute>开始和结束标记折叠在一行之外,还有什么办法可以实现吗?
因为如果属性值不是简单的文本行而是一些复杂计算的结果(例如使用或标记),那么将一行中的所有代码折叠以避免前导和尾随空格将导致可怕的丑陋样式表.