简体   繁体   中英

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. 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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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