xslt中的元素的单独文本(来自xml)

时间:2018-01-15 09:34:17

标签: html xml xslt dtd

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>

1 个答案:

答案 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>

请参阅http://xsltransform.net/jxN8NpA

上的转化