我不确定您要做什么,但您可以尝试以下操作。源 XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Result>
<resultDetails>
<resultDetailsData>
<itemProperties>
<ID>1</ID>
<type>LEVEL</type>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">5</value>
</itemProperties>
</resultDetailsData>
</resultDetails>
</Result>
应用此 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="itemProperties">
<xsl:variable name="fromOutputTemplate">
<xsl:call-template name="output"/>
</xsl:variable>
<out>
<xsl:value-of select="$fromOutputTemplate"/>
</out>
</xsl:template>
<xsl:template name="output">
<xsl:variable name="spaces" select = "'            '"/>
<xsl:variable name="myVar" select = "value"/>
<xsl:choose>
<xsl:when test="type='LEVEL'">
<xsl:value-of select="substring($spaces, 1, $myVar)"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
它为您提供以下输出:
<?xml version="1.0" encoding="UTF-8"?>
<out> </out>
那是你想走的路吗?