Read in XML in order with XSLT -


i'd read xml file in order can't.

in fact have xml :

<?xml version="1.0"?> <bookings>     <booking>         <id>424242</id>         <number>01010101</number>         <info>             <color>blue</color>             <height>1</height>         </info>     </booking>     <booking>         <id>9999</id>         <number>777</number>         <info>             <color>black</color>             <height>2</height>         </info>     </booking> </bookings> 

actually use xsl 1 below :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" />  <xsl:template match="/">     <xsl:text>id|number|color|height</xsl:text>     <xsl:text>&#xa;</xsl:text>     <xsl:apply-templates select="bookings"/>      </xsl:template>  <xsl:template match="bookings">     <xsl:apply-templates select="booking"/>     <xsl:apply-templates select="booking/info"/>     <xsl:text>&#xa;</xsl:text> </xsl:template>  <xsl:template match="booking">     <xsl:value-of select="id"/>     <xsl:text>|</xsl:text>     <xsl:value-of select="number"/>     <xsl:text>|</xsl:text> </xsl:template>  <xsl:template match="info">     <xsl:value-of select="color"/>     <xsl:text>|</xsl:text>     <xsl:value-of select="height"/>     <xsl:text>&#xa;</xsl:text> </xsl:template>  </xsl:stylesheet> 

so excpected output:

id|number|color|height 424242|01010101|blue|1 9999|777|black|2 

but got :

id|number|color|height 424242|01010101|9999|777|blue|1 black|2 

anyone got solution or maybe link can learn how ? because don't find friend google.

thanks, , sorry bad english.

all need here move apply-templates selecting booking/info template matching booking (and select info)

at moment, listing bookings first, , list info elements.

try xslt

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text" />  <xsl:template match="/">     <xsl:text>id|number|color|height</xsl:text>     <xsl:text>&#xa;</xsl:text>     <xsl:apply-templates select="bookings"/>      </xsl:template>  <xsl:template match="bookings">     <xsl:apply-templates select="booking"/>     <xsl:text>&#xa;</xsl:text> </xsl:template>  <xsl:template match="booking">     <xsl:value-of select="id"/>     <xsl:text>|</xsl:text>     <xsl:value-of select="number"/>     <xsl:text>|</xsl:text>     <xsl:apply-templates select="info"/> </xsl:template>  <xsl:template match="info">     <xsl:value-of select="color"/>     <xsl:text>|</xsl:text>     <xsl:value-of select="height"/>     <xsl:text>&#xa;</xsl:text> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -