【发布时间】:2016-02-10 22:55:09
【问题描述】:
StackExchange,我希望这里有人可以帮助我解决这个问题!
我正在使用 XSLT 1.0,尝试嵌入一个查找表以将一些未格式化的数据转换为标准化的格式化结构。
我已阅读并搜索并尝试了各种方法来完成此操作,但没有一个能够产生结果。 (虽然我也没有收到任何错误。)
以下是我正在使用的 XSL 示例:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:lookup="lookup" exclude-result-prefixes="lookup">
<xsl:key name="lookup_table" match="lookup:table/row" use="@raw"/>
<lookup:table>
<row raw="raw1" corrected="Raw One"/>
<row raw="raw2" corrected="Raw Two"/>
<row raw="raw3" corrected="Raw Three"/>
<row raw="raw4" corrected="Raw Four"/>
<row raw="raw5" corrected="Raw Five"/>
</lookup:table>
<xsl:template match="/">
<xsl:variable name="lookup_table" select='document("")//lookup:table/row'/>
<xsl:variable name="value_to_lookup" select="'raw1'"/>
<!-- In the actual XSL document, this variable would use an XPath to point to another attribute. -->
<!-- In this case, the value of this variable must be changed manually. -->
<xsl:value-of select='document("")//lookup:table/row[@raw = $value_to_lookup]/@corrected'/>
<xsl:value-of select='document("")//lookup:table[@raw = $value_to_lookup]/@corrected'/>
<xsl:value-of select='$lookup_table[@raw = $value_to_lookup]/@corrected'/>
<xsl:value-of select="key('lookup_table',$value_to_lookup)/@corrected"/>
<!-- The above lines are the various methods I've seen documented on other websites that claim these methods should allow me to what I need to. -->
<!-- There is no need to have multiple identical results, I only have multiple attempts here to document the steps I have tried. -->
</xsl:template>
</xsl:stylesheet>
这段代码的当前输出什么都没有(字面意思)。
当变量value_to_lookup等于“raw1”时,期望的输出是:
Raw One
为了进一步说明,当变量value_to_lookup 等于“raw4”时所需的输出是:
Raw Four
这段代码的输出将存储在一个变量中,并在需要时调用。
再次感谢!
【问题讨论】:
标签: xml xslt lookup lookup-tables