【发布时间】:2016-02-12 06:29:16
【问题描述】:
所以我有这个我正在课堂上处理的 XML 文档。
<etymology>The <a href="https://en.wikipedia.org/wiki/Yakama">Yakama</a> Native American tribe</etymology>
它在词源元素中包含一个 href。默认情况下,当 XSLT 对此进行转换时,链接会以仅显示文本且不再链接到另一个页面的方式“停用”。
我需要知道在这里做什么:
<td width="25%">
<xsl:value-of select="etymology"/>
</td>
这样,在 Etymology 元素中可能存在的链接将被翻译或显示为链接,而不是转换为纯文本。
我在样式表中定义的当前和唯一的模板是这样的:
<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>
最后是我正在转换的 XML 文件: http://puu.sh/n4XiV.xml
【问题讨论】:
-
这是一个很好的例子,为什么您需要发布 minimal reproducible example 而不是脱离上下文的 sn-ps。
-
请在您的问题中发布您的 XML(最好是最小化)。
-
我无法发布 XML 文件,因为它超过了 30000 个字符的限制。
-
您显然没有阅读上面的链接。具体来说,“Minimal – 使用尽可能少的代码,但仍会产生同样的问题”部分。