2013-07-29 135 views
2

我想重命名mattext节点的文本,但保留其属性和所有的子节点/属性重命名元素,并保留属性

输入XML

<material> 
    <mattext fontface="Tahoma"> 
    <p style="white-space: pre-wrap"> 
     <font size="11">Why are the astronauts in the video wearing special suits? (Select two)</font> 
    </p> 
    </mattext> 
</material> 

输出

<material> 
    <text fontface="Tahoma"> 
    <p style="white-space: pre-wrap"> 
     <font size="11">Why are the astronauts in the video wearing special suits? (Select two)</font> 
    </p> 
    </text> 
</material> 

我已经使用了以下xsl:

<xsl:template name="content"> 
    <xsl:copy> 
     <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
</xsl:template> 


<!-- Build stem --> 
<xsl:template match="mattext"> 
    <text> 
     <!-- Option text --> 
     <xsl:call-template name="content"/> 
    </text> 
</xsl:template> 

但它不会保留初始fontface属性,似乎输出明文剥离标签

回答

3

我能理解你的结果,如果这是你的完整的XSLT。您正在匹配一个元素,即< mattext>。所有其他处理都由复制文本节点的默认行为处理。我想你想Identity Transformation与< mattext>元素:

<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()" /> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="mattext"> 
    <text> 
     <xsl:apply-templates select="@* | node()" /> 
    </text> 
</xsl:template> 
+0

完美的作品!谢谢 – Rob