This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: re-ordering nodes




> Actually I was being lazy. I think that what Srini wanted was:

Jeni, Wendell - 

Thanks for your responses. They were useful, and I was able to play with
it and get what I need.

I ended up writing a SAX parser, and compared it with a small XSL
script, based on your suggestions. I am amazed, at how easy it is with
XSL once you get the hang of it.

And, Sorry folks, for not being too clear. I am researching on how an XML
object model (objects serialized in XML) retrofit over a relational
database can communicate with applications. For simplicity, I designed it
so that all the objects ("<o>" tags with oids) are at the root level with
references from other objects. However, while generating the object data
from relational SQL queries, it is far easier to nest them. So, I thought
of a post-processing step that re-orders all the objects, and bring them
at the same level.

Does anyone know of other tools or similar efforts? Once again, thanks for
all your input.

-Srini

> 
> <xsl:strip-space elements="*" />
> 
> <xsl:template match="list">
>   <xsl:apply-templates select=".//o">
>     <xsl:sort select="count(node())" data-type="number" />
>   </xsl:apply-templates>
> </xsl:template>
> 
> <xsl:template match="o">
>   <o>
>     <xsl:apply-templates select="a | b | text()" />
>   </o>
> </xsl:template>
> 
> <xsl:template match="a | b">
>   <xsl:copy>
>     <xsl:copy-of select="@*" />
>     <xsl:if test="o">
>       <xsl:comment>
>         <xsl:text> for </xsl:text>
>         <xsl:for-each select=".//o[not(o)]">
>           <xsl:value-of select="number()" />
>           <xsl:if test="position() != last()">, </xsl:if>
>         </xsl:for-each>
>         <xsl:text> </xsl:text>
>       </xsl:comment>
>     </xsl:if>
>   </xsl:copy>
> </xsl:template>
> 
> At least it gives the required output for the single sample
> document...
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]