xslt 从字符串创建有序列表 [英] xslt create ordered list from string

查看:27
本文介绍了xslt 从字符串创建有序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 xml 中有一个字符串

1. 第一个列表项.2. 第二个列表项.3. 第三个列表项.</匿名者>

是否可以创建这样的有序列表:

    <li>第一个列表项.</li><li>第二个列表项.</li><li>第三个列表项.</li></ol>

解决方案

有可能,但必须是字符串操作,这意味着在某些情况下,如果文本比这更复杂,则可能无法实现.

>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"排除结果前缀=xs xd"版本=2.0"><xsl:template match="/"><xsl:apply-templates/></xsl:模板><xsl:template match="anons"><ol><xsl:for-each select="tokenize (./string(), '\d+\.')[normalize-space()]"><li><xsl:value-of select="normalize-space(.)"/></li></xsl:for-each></ol></xsl:模板></xsl:stylesheet>

Have a string in xml

<anons>
      1. first list item. 2. second list item. 3. third list item.
</anons>

Is it possible to create an ordered list like this:

<ol>
  <li>first list item.</li>
  <li>second list item.</li>
  <li>third list item.</li>
</ol>

解决方案

It is possible but it would have to be a string operation, meaning it might not be possible in some cases if the text is more complex than this.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="2.0">

<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="anons">
    <ol>
        <xsl:for-each select="tokenize (./string(), '\d+\.')[normalize-space()]">
                <li><xsl:value-of select="normalize-space(.)"/></li>
        </xsl:for-each>
    </ol>
</xsl:template>

</xsl:stylesheet>

这篇关于xslt 从字符串创建有序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆