简体   繁体   English

如何使用XSLT在文本节点值中的位置获取字符串?

[英]How to get string at position in text node value using XSLT?

I am trying to use the below XSLT to transform my XML document, and the transformation is working fine. 我正在尝试使用下面的XSLT转换我的XML文档,并且转换工作正常。 What I need now is to be able to get the first set of numbers before the space character inside list item text node value. 我现在需要的是能够获得列表项文本节点值内的空格字符之前的第一组数字。 The purpose is to use it inside the <doc:id> 目的是在<doc:id>使用它

I have tried: 我努力了:

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

        <location>


            <xsl:value-of select="concat('http://localhost/auto/teo',mydoc)"></xsl:value-of>
           <test>
               <xsl:for-each select="text()[1]">
                   <xsl:value-of select="."/>
               </xsl:for-each>

           </test>
        </location>
            <extension >

                  <doc:id>

                      <xsl:number value="position()" format="01" />
                    </doc:id>

            </extension>
        </document>
</xsl:template>

And here is the source document for transformation: 这是转换的源文档:

<html>
<head>
  <title></title>
</head>
<body>

  <!-- This is my first comment -->
 <ol>
    <li>1 data</li>
    <li>2 data</li>
    <li>3 data</li>
    <li>4 data</li>
    <li>5 data</li>
    <li>6 data</li>
    <li>7 data</li>
    <li>8 data</li>
    <li>9 data</li>
    <li>10 data</li>
    <li>11 data</li>
    <li>12 data</li>
    <li>13 data</li>
 </ol>
</body>
</html>

Please try the following: 请尝试以下操作:

<doc:id>
   <xsl:number value="substring-before(., ' ')" format="01" />
</doc:id>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM