我正在尝试根据检查是否匹配某个模式来更新xml中的文本节点
在xslt 1.0中
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:regexp="http://exslt.org/regular-expressions">
<xsl:output method="xml" version="1.0"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:copy>
<xsl:call-template name="CheckAndReplace">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="pattern" select=""/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="CheckAndReplace">
<xsl:param name="text"/>
<xsl:param name="pattern"/>
<xsl:for-each select="regexp:match( $text, $pattern, 'gi' )">
<xsl:copy-of select="regexp:replace( $text, $pattern, 'gi','*' )"
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>XML:
<Root>
<Name> Kabir </Name>
<Id>  </Id>
</Root>这里的请求具有与我的模式匹配的ID标记,需要替换
结果要求:
<Root>
<Name> Kabir </Name>
<Id> * </Id>
</Root>发布于 2019-02-07 21:22:34
XSLT 1.0中没有正则表达式。如果您的目标是用*替换所有出现的字符,请尝试:
<xsl:template match="text()">
<xsl:value-of select="translate(., '', '*')" />
</xsl:template>https://stackoverflow.com/questions/54568550
复制相似问题