我正在編寫的轉換必須從給定節點集組成一個以逗號分隔的字符串值。結果字符串必須根據輸入值中第一個字符的隨機(非字母)映射進行排序。使用字段子字符串的XSL關聯排序
我想出了這一點:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tmp="http://tempuri.org"
exclude-result-prefixes="tmp"
>
<xsl:output method="xml" indent="yes"/>
<tmp:sorting-criterion>
<code value="A">5</code>
<code value="B">1</code>
<code value="C">3</code>
</tmp:sorting-criterion>
<xsl:template match="/InputValueParentNode">
<xsl:element name="OutputValues">
<xsl:for-each select="InputValue">
<xsl:sort select="document('')/*/tmp:sorting-criterion/code[@value=substring(.,1,1)]" data-type="number"/>
<xsl:value-of select="normalize-space(.)"/>
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
它不工作,看起來像XPath的document('')/*/tmp:sorting-criterion/code[@value=substring(.,1,1)]
如我所料不評估。我已經檢查了將substring(.,1,1)
替換爲文字,並將其評估爲適當的值。
那麼,我是否遺漏了一些讓排序XPath表達式不按照我期望的那樣進行評估的問題,還是僅僅通過這種方式來強制執行?
如果無法創建可以工作的XPath表達式,是否有解決方法來實現我的目的?
注:我受限於XSLT的1.0
樣品輸入:
<?xml version="1.0" encoding="utf-8"?>
<InputValueParentNode>
<InputValue>A input value</InputValue>
<InputValue>B input value</InputValue>
<InputValue>C input value</InputValue>
</InputValueParentNode>
預計輸出繼電器:
<?xml version="1.0" encoding="utf-8"?>
<OutputValues>B input value,C input value,A input value</OutputValues>
你能提供例如輸入和預期的輸出? – wdebeaum 2010-12-15 15:35:54
@wdebeaum:編輯的問題包括兩個。乾杯。 – 2010-12-15 15:52:06