您可以定義要替換和替換字符的字符,然後使用translate
。 您可以使用此XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="in">12</xsl:variable>
<xsl:variable name="out">AX</xsl:variable>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@attr1">
<xsl:attribute name="attr1">
<xsl:value-of select="translate(., $in, $out)"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
另一種方式:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@attr1">
<xsl:choose>
<xsl:when test=". = '1'">
<xsl:attribute name="attr1">
<xsl:text>A</xsl:text>
</xsl:attribute>
</xsl:when>
<xsl:when test=". = '2'">
<xsl:attribute name="attr1">
<xsl:text>X</xsl:text>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<xsl:template match="@attr1">
將匹配所有屬性attr1
,然後使用xsl:choose
你創建這個屬性適當的值。
爲了適應運行定製,改變'的xsl:variable'到'XSL :param'。 –