感谢您的帮助!对此,我真的非常感激!我明白为什么我需要将值放在节点中,但我没有使用模板但使用了函数......我只是无法弄清楚如何将这些节点和模板放入函数中?转换输出`>`而不是`>`
如果我只显示我的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