感謝您的幫助!對此,我真的非常感激!我明白爲什麼我需要將值放在節點中,但我沒有使用模板但使用了函數......我只是無法弄清楚如何將這些節點和模板放入函數中?轉換輸出`>`而不是`>`
如果我只顯示我的XSLT文件,可能會更容易。下面你可以找到該文件,並讓說,例如這可能是$字符串把它傳遞給函數(不轉換XML文件):
<img src="Afbeeldingen Hotpot/beer.jpg" alt="afbeelding van een beer" title="beer" width="170" height="144" style="display:block; margin-left:auto; margin-right:auto; text-align:center;" style="float:center;" />
這是XSLT文件的完整內容:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:foo="http://www.wathever.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs functx"
xmlns:functx="http://www.functx.com">
<xsl:import href="alle-functx-functies.xsl"/>
<xsl:function name="foo:functionIfImage">
<xsl:param name="string" as="xs:string"/>
<xsl:if test="contains($string,'.jpg')">
<xsl:sequence select="foo:functionImage($string,'.jpg')"/>
</xsl:if>
<xsl:if test="contains($string,'.png')">
<xsl:sequence select="foo:functionImage($string,'.png')"/>
</xsl:if>
<xsl:if test="contains($string,'.gif')">
<xsl:sequence select="foo:functionImage($string,'.png')"/>
</xsl:if>
<xsl:if test="not(contains($string,'.jpg')) and not(contains($string,'.png')) and not(contains($string,'.gif'))">
<xsl:sequence select="'iumi ondersteund alleen afbeeldingen van het formaat *.jpg, *.png of *.gif'"/>
</xsl:if>
<xsl:if test="not(contains($string,'img src='))">
<xsl:sequence select="'bevat geen img src='"/>
</xsl:if>
</xsl:function>
<xsl:function name="foo:functionImage">
<xsl:param name="string" as="xs:string"/>
<xsl:param name="type" as="xs:string"/>
<xsl:variable name="quot">"</xsl:variable>
<xsl:variable name="beforePath" as="xs:string">img src="</xsl:variable>
<xsl:variable name="globalPath" as="xs:string" select="substring-before(substring-after($string, $beforePath), $quot)" />
<xsl:variable name="beforeWidth" as="xs:string">width="</xsl:variable>
<xsl:variable name="width" as="xs:string" select="substring-before(substring-after($string, $beforeWidth), $quot)" />
<xsl:variable name="beforeHeight" as="xs:string">height="</xsl:variable>
<xsl:variable name="height" as="xs:string" select="substring-before(substring-after($string, $beforeHeight), $quot)" />
<xsl:if test="not(contains($globalPath,'http'))">
<xsl:variable name="fileName" as="xs:string"><xsl:sequence select="functx:substring-after-last($globalPath,'/')"/></xsl:variable>
<xsl:variable name="compatibleData" as="xs:string">
<xsl:sequence select="concat('<img source="images/',$fileName,'"',' width="',$width,'" height="',$height,'" />')"/>
</xsl:variable>
<xsl:value-of disable-output-escaping= "yes" select="$compatibleData" />
</xsl:if>
<xsl:if test="contains($globalPath,'http')">
<xsl:variable name="compatibleData" as="xs:string">
<xsl:sequence select="concat('<img source="',$globalPath,'"',' width="',$width,'" height="',$height,'" />')"/>
</xsl:variable>
<xsl:value-of disable-output-escaping= "yes" select="$compatibleData" />
</xsl:if>
</xsl:function>
</xsl:stylesheet>
所以這一塊我的XSLT代碼給我錯誤的輸出:
改造後<xsl:variable name="compatibleData" as="xs:string">
<xsl:sequence select="concat('<img source="',$globalPath,'"',' width="',$width,'" height="',$height,'" />')"/>
</xsl:variable>
<xsl:value-of disable-output-escaping= "yes" select="$compatibleData" />
輸出:
<img source="images/beer.jpg" width="300" height="300" />
輸出我想改造後:
<img source="images/beer.jpg" width="300" height="300" />
我怎樣才能使輸出說<
代替<
,並>
代替>
? value-of disable-output-escaping =「yes」不起作用...
問得好,+1 。看到我的答案爲最短,最簡單,最容易理解/可維護的解決方案:) – 2011-05-07 23:03:43