my templates (XSLT 1.0)
<xsl:template name="doo">
<xsl:variable name="nodelist">
<root>
<a size="12" number="11">
<sex>male</sex>
Hulk
</a>
<a size="12" number="11">
<sex>male</sex>
Steven XXXXXXXXXXX
</a>
</root>
</variable>
<xsl:call-template name="findString">
<xsl:with-param name="content1" select="$nodelist"></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="findString">
<xsl:param name="content1" select="."></xsl:param>
<!-- here i need to search the text() XXXXXXXXXXX from $content1 and replace them-->
</xsl:template>
是否可能像
for each node in Tree Fragment from myvariable
if node/text()='xxxxxxxx'
do something
对于xslt version=1.0,您可以使用扩展名"not-set"。
<xsl:call-template name="findString">
<xsl:with-param name="content1" select="exsl:node-set($nodelist)"></xsl:with-param>
</xsl:call-template>
要使它醒来,你必须添加以下行:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
version="1.0">
更新:基于Mads Hansen的解决方案
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:template name="doo">
<xsl:variable name="nodelist">
<root>
<a size="12" number="11">
<sex>male</sex>
Hulk
</a>
<a size="12" number="11">
<sex>male</sex>
Steven XXXXXXXXXXX
</a>
</root>
</xsl:variable>
aaa
<xsl:call-template name="findString">
<xsl:with-param name="content1" select="exsl:node-set($nodelist)"></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="doo" />
</xsl:template>
<xsl:template name="findString">
<xsl:param name="content1" select="."></xsl:param>
<!-- here i need to search the text() XXXXXXXXXXX from $content1 and replace them-->
<xsl:apply-templates mode="mytext" select="$content1"/>
</xsl:template>
<!--Identity template will copy all matched nodes and apply-templates-->
<xsl:template match="@*|node()" mode="mytext">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="mytext"/>
</xsl:copy>
</xsl:template>
<!--Specialized template to match on text nodes that contain the "findString" value-->
<xsl:template match="text()[contains(.,'XXXXXXXXXXX')]" mode="mytext">
<xsl:variable name="findString" select="'XXXXXXXXXXX'"/>
<xsl:variable name="replaceString" select="'YYYYYYYYYYYY'"/>
<xsl:value-of select="concat(substring-before(., $findString),
$replaceString,
substring-after(., $findString))"/>
</xsl:template>
</xsl:stylesheet>