我试图在XSL中模拟StringBuilder行为.有没有办法做到这一点.鉴于XSLT是一种函数式编程语言,这似乎很难 如果你正在查看一个节点集(只要你可以构造xpath来找到节点集),你就可以通过一点点
尝试这个为初学者(也加入):
<xsl:template match="/">
<xsl:variable name="s">
<xsl:call-template name="stringbuilder">
<xsl:with-param name="data" select="*" /><!-- your path here -->
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$s" /><!-- now contains a big concat string -->
</xsl:template>
<xsl:template name="stringbuilder">
<xsl:param name="data"/>
<xsl:param name="join" select="''"/>
<xsl:for-each select="$data/*">
<xsl:choose>
<xsl:when test="not(position()=1)">
<xsl:value-of select="concat($join,child::text())"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="child::text()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
可能需要对此进行各种扩展:也许您想要修剪,也许您想要通过层次结构进行隧道传输.我不确定是否存在防弹通用解决方案.
