Reputation: 347
My input is having URL, this needs to come in both attribute value and content value in the output using XSL:
My Input xml is:
<link>
<Url>http://tneb.gov/</Url>
</link>
XSL I Used as:
<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>
Output I get as:
<xref format="html" href="http://tneb.gov/"/>
But i need as:
<xref format="html" href="http://tneb.gov/">http://tneb.gov/</xref>
Please give me suggestion on this. Thanks in advance
Upvotes: 0
Views: 55
Reputation: 116993
Why don't you do simply:
<xsl:template match="Url">
<xref format="html" href="{.}">
<xsl:value-of select="."/>
</xref>
</xsl:template>
Notes:
It's not necessary to use xsl:element
if the name of the element is
known - see: https://www.w3.org/TR/xslt20/#literal-result-element
Learn about attribute value templates: https://www.w3.org/TR/xslt20/#attribute-value-templates
Learn about the context item expression: https://www.w3.org/TR/xpath20/#id-context-item-expression
Upvotes: 1