0
我正在嘗試從XML中更改一些文本。但它沒有奏效。使用XSLT更改文本
我要顯示所有從XML [intro]
文本的某些Path(text)
顯示[intro]
之前應該改變。
例如
<a href="3DD3D025-2236-49C9-A169-DD89A36DA0E6/eee.pdf"> --> wrong path
我想改變
<a href="Content\3\D\D\3DD3D025-2236-49C9-A169-DD89A36DA0E6/eee.pdf">
任何幫助將不勝感激。
示例XML
<?xml version="1.0"?>
<root>
<intro xml:lang="en">
<div class="blueBar">
<h2>Highlights</h2>
<ul>
<li><a href="http://xxx/xxx/default.asp?lang=En">aaaa</a></li>
<li><a href="http://xxx/default.asp?lang=En">bbbb</a></li>
<li><a href="http://xxx/Content/1/C/D/1CD1DFC3-5149-4D61-A7C3-2D9CF7E65F8C/rrr.pdf">ccc</a></li>
<li><a href="3DD3D025-2236-49C9-A169-DD89A36DA0E6/eee.pdf">pdf</a></li>
</ul>
</div>
</intro>
<intro> .....</intro>
</root>
樣品XSLT
<xsl:param name="language"/>
<xsl:template match="root">
<xsl:for-each select="intro[lang($language)]//@href">
<xsl:choose>
<xsl:when test="contains(.,'pdf') and not(contains(.,'Content'))">
<xsl:variable name="pdfGuid">
<xsl:value-of select="substring(.,0,36)"/>
</xsl:variable>
<xsl:variable name="pdfPath">
<xsl:value-of select="concat('/','Content')"/>
<xsl:value-of select="concat('/', substring($pdfGuid, 1,1))"/>
<xsl:value-of select="concat('/', substring($pdfGuid, 2,1))"/>
<xsl:value-of select="concat('/', substring($pdfGuid, 3,1))"/>
<xsl:value-of select="concat('/', $pdfGuid)"/>
</xsl:variable>
<xsl:value-of select="strJS:replace(string(.),string($pdfGuid),string($pdfPath))" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<div class="greenBox">
<xsl:value-of select="intro[lang($language)]" disable-output-escaping="yes"/>
</div>
</xsl:template>
的XSLT是沒有意義的。什麼是 'do?你爲什麼使用'disable-output-escaping'?你可以做一個小的,充分的,充分的例子你有什麼作爲XML和你想要在輸出。 –
kan
2013-05-08 21:16:45