XML
<product>
<name>Smartphone Samsung S6</name>
</product>
<product>
<name>Smartphone Samsung S8</name>
</product>
HTML
<h1>Smartphone<small>Samsung S6</small></h1>
<h1>Smartphone<small>Samsung S8</small></h1>
我如何在xslt中执行此操作?输出:html
<xsl:for-each select="product">
<h1><xsl:value-of select="name"/></h1>
</xsl:for-each>
答案 0 :(得分:0)
试试这个:
<xsl:for-each select="product">
<h1>
<xsl:analyze-string select="name" regex="^(Smartphone) (Samsung S[0-9])">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
<small>
<xsl:value-of select="regex-group(2)"/>
</small>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</h1>
</xsl:for-each>
上的转化