需要包含属性和内容的URL

时间:2017-02-01 05:10:16

标签: xslt

我的输入是URL,这需要使用XSL输出属性值和内容值:

我的输入xml是:

<link>
<Url>http://tneb.gov/</Url>
</link>

XSL我用作:

<xsl:stylesheet version="2.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="Url">
    <xsl:element name="xref">
      <xsl:attribute name="format">
        <xsl:text>html</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="href">
        <xsl:value-of select="ancestor-or-self::link/Url"/>
      </xsl:attribute>
     </xsl:element>
   </xsl:template>

</xsl:stylesheet>

输出我得到:

<xref format="html" href="http://tneb.gov/"/>

但我需要:

<xref format="html" href="http://tneb.gov/">http://tneb.gov/</xref>

请给我这个建议。提前致谢

1 个答案:

答案 0 :(得分:1)

为什么你不做:

<xsl:template match="Url">
    <xref format="html" href="{.}">
        <xsl:value-of select="."/>
    </xref>
</xsl:template>

备注