使用
xsl:value-of
只会为您提供一个计算文本节点。不会进行任何其他处理,因此您的其他模板匹配 text()
将永远不会被匹配。
此外,如果您使用
xsl:apply-templates
,则其他 text()
模板将无法工作,因为 substring-after()
返回 xs:string 而不是 text() 节点。
作为替代方案,尝试使用 xsl:next-match 并删除其他模板中的
!!!
...
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="2.0">
<xsl:output indent="true"/>
<xsl:template match="text()[starts-with(., '!!!')]" priority="5" name="note">
<fo:block>
<fo:external-graphic src="TBD.png" content-width="scale-to-fit" width="23px"/>
<fo:block>
<fo:inline>NOTE: </fo:inline>
<xsl:next-match/>
</fo:block>
</fo:block>
</xsl:template>
<xsl:template match="text()[contains(., '@v')]" name="varname" priority="4">
<xsl:analyze-string select="." regex="(^!!!\s*)?(.*?)@v\s+([!-~]+)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(2)"/>
<fo:inline font-family="Roboto" font-style="italic">
<xsl:value-of select="regex-group(3)"/>
</fo:inline>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
两个模板都匹配文本节点,但第一个模板具有更高的优先级,因此使用第一个模板。如果您希望应用两个模板规则,则需要通过显式应用模板来进行安排,例如将第一个模板规则的内部
fo:block
更改为
<fo:block xsl:use-attribute-sets="note__text__note">
<fo:inline xsl:use-attribute-sets="note__label">NOTE: </fo:inline>
<xsl:variable name="remainder" as="text()">
<xsl:value-of select="substring-after(., '!!!')"/>
<xsl:variable>
<xsl:apply-templates select="$remainder"/>
</fo:block>