简体   繁体   中英

xslt 1.0 match two subsequent elements

I have an XML file with subsequent elements that I want to insert in single paragraph

Here is the XML format

<root>
    <list>
        <file> 1.txt </file>
        <url> site.com </url>
        <file> 2.text </file>
        <url> mysite.com </url>
        <file> 3.gif </file>
        <url> picsite.com </url>
    </list>

</root>

I want to select each two subsequent elements so the results will be like :

1.txt , site.com
2.txt, mysite.com
3.gif, picsite.com

It's look like simple task but I didn't found any elegant solution for that... Any sugstions ?

I'm working on XSLT 1.0 version

This should work, as musiKk suggested,

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="/">
  <xsl:for-each select="/root/list/file">
   <xsl:value-of select="normalize-space(.)"/>,  <xsl:value-of select="normalize-space(following-sibling::*)"/> 
    <xsl:text>
    </xsl:text>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

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