XML代码:
<window>
<control name="txt" a="1" b="2">value</control>
</window>
Xslt代码:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="utf-8" method="html" />
<xsl:template match="/">
<div>
<xsl:apply-templates select="window/control[@name='txt']">
<xsl:with-param name="size">7</xsl:with-param>
</xsl:apply-templates>
</div>
</xsl:template>
<xsl:template match="control">
<xsl:param name="size" />
Text:
<input type="text">
<xsl:attribute name="value"><xsl:value-of select="$size"/></xsl:attribute>
</input>
<xsl:for-each select="attribute::*">
<xsl:value-of select="name()"/>=<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
用<xsl:with-param name="size">传值
另外attribute::*也是一个很cool的写法哦
输出结果:
<div>
Text:
<input type="text" value="7">name=txta=1b=2
</div>