8,906
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="GB2312" standalone="yes"?>
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output indent="yes"/>
<xsl:variable name="content" select="'p1;p2;p3;p4'"/>
<xsl:template name="main">
<xsl:call-template name="format">
<xsl:with-param name="source" select="$content"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="format">
<xsl:param name="source" as="xs:string"/>
<xsl:analyze-string regex="^([^;]+);(.*)$" select="$source">
<xsl:matching-substring>
<p>
<xsl:value-of select="regex-group(1)"/>
</p>
<xsl:call-template name="format">
<xsl:with-param name="source" select="regex-group(2)"/>
</xsl:call-template>
</xsl:matching-substring>
<xsl:non-matching-substring>
<p>
<xsl:value-of select="$source"/>
</p>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
解析器:Saxon
java net.sf.saxon.Transform -xsl:test.xslt -it:main
result:
<?xml version="1.0" encoding="UTF-8"?>
<p xmlns:xs="http://www.w3.org/2001/XMLSchema">p1</p>
<p xmlns:xs="http://www.w3.org/2001/XMLSchema">p2</p>
<p xmlns:xs="http://www.w3.org/2001/XMLSchema">p3</p>
<p xmlns:xs="http://www.w3.org/2001/XMLSchema">p4</p>