Reputation: 31
So i have this piece of an XML document I'm working on in class.
<etymology>The <a href="https://en.wikipedia.org/wiki/Yakama">Yakama</a> Native American tribe</etymology>
it contains a href within the element of Etymology. When the XSLT transforms this by default, the link gets 'deactivated' in a way that only the text shows and it no longer links out to another page.
I need to know what to do here:
<td width="25%">
<xsl:value-of select="etymology"/>
</td>
So that the links as many as there may be in the Etymology element will translate or appear as a link and not transform into plain text.
My current and ONLY template defined in the stylesheet is this:
<xsl:template match="/">
<html>
<head>
<title>Washington Counties</title>
</head>
<body>
<h1>Washington Counties</h1>
<p>
( <a><xsl:attribute name="href">
<xsl:value-of select="counties/@source" />
</xsl:attribute>
data source</a> )
</p>
<table border="1" style="border-collapse: collapse;">
<tr><th>County</th><th>INCITS</th><th>County Seat</th><th>Established</th><th>Origin</th><th>Etymology</th><th>Population</th><th>Area</th><th>Map</th>
</tr>
<xsl:for-each select="counties/county">
<xsl:sort select="established" order="ascending" data-type="number" />
<tr>
<td>
<xsl:choose>
<xsl:when test="name = 'Grays Harbor County'" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<xsl:value-of select="name" />
</a>
<sup><a href="#b">b</a></sup>
</xsl:when>
<xsl:when test="name = 'Mason County'" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<xsl:value-of select="name" />
</a>
<sup><a href="#c">c</a></sup>
</xsl:when>
<xsl:when test="name = 'Kitsap County'" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<xsl:value-of select="name" />
</a>
<sup><a href="#d">d</a></sup>
</xsl:when>
<xsl:when test="name = 'Clark County'" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<xsl:value-of select="name" />
</a>
<sup><a href="#e">e</a></sup>
</xsl:when>
<xsl:when test="name = 'Yakima County'" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<xsl:value-of select="name" />
</a>
<sup><a href="#f">f</a></sup>
</xsl:when>
<xsl:when test="name = 'Jefferson County'" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<xsl:value-of select="name" />
</a>
<sup><a href="#g">g</a></sup>
</xsl:when>
<xsl:when test="name = 'Clallam County'" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<xsl:value-of select="name" />
</a>
<sup><a href="#g">g</a></sup>
</xsl:when>
<xsl:otherwise>
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<xsl:value-of select="name" />
</a>
</xsl:otherwise>
</xsl:choose>
</td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="incits/@href" />
</xsl:attribute>
<xsl:value-of select="incits" /></a>
</td>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="countySeat/@href" />
</xsl:attribute>
<xsl:value-of select="countySeat" /></a>
</td>
<td>
<xsl:choose>
<xsl:when test="established = 1879">
<xsl:value-of select="established" /> <sup>
<a href="#a">a</a>
</sup>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="established" />
</xsl:otherwise>
</xsl:choose>
</td>
<td>
<xsl:choose>
<xsl:when test="origin != 0">
<xsl:value-of select="origin" />
</xsl:when>
<xsl:otherwise>
Original County
</xsl:otherwise>
</xsl:choose>
</td>
<td width="25%">
<xsl:value-of select="etymology"/>
</td>
<td><xsl:value-of select="population" /></td>
<td><xsl:value-of select="area[@unit='mi2']" /> sq mi
<br />(<xsl:value-of select="area[@unit='km2']" /> sq km)
</td>
<td>
<img>
<xsl:attribute name="src">
<xsl:value-of select="map/@src" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="./name" />
</xsl:attribute>
</img>
</td>
</tr>
</xsl:for-each>
</table>
<br />
<strong>Footnotes</strong>
<br />
<xsl:for-each select="counties/footnote">
<p>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:value-of select="@id" />. <xsl:value-of select="."/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>
and lastly the XML file I am transforming: http://puu.sh/n4XiV.xml
Upvotes: 0
Views: 235
Reputation: 117100
Instead of:
<xsl:value-of select="etymology"/>
do:
<xsl:apply-templates select="etymology/node()"/>
and make sure you have a templates that copy a
and text nodes.
Upvotes: 0
Reputation: 31193
xsl:value-of
will, as the name says, only take the value of the node. You need to use xsl:apply-templates
for the processor to continue processing the contents as they are.
Since the default action is to copy, you will get everything inside the tag in the output.
Upvotes: 1