[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Converting a node tree to a textual representation

Subject: RE: Converting a node tree to a textual representation
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 3 Sep 2006 07:15:25 +0100
simple node tree
If you're using Saxon you could use saxon:serialize(). Or you could use Evan
Lenz's serializer implemented in XSLT:
http://www.stylusstudio.com/xsllist/200105/post61330.html

Michael Kay
http://www.saxonica.com/

 

> -----Original Message-----
> From: Houghton,Andrew [mailto:houghtoa@xxxxxxxx] 
> Sent: 03 September 2006 06:18
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Converting a node tree to a textual representation
> 
> 
> I'm using XSL 2.0 to create a CSV text file.  One of the 
> columns needs to be a textual representation of a portion of 
> the source document.  The source document looks something like:
> 
> <doc>
>   <lvl>
>     <rec>
>       <sect1/>
>       <sect2/>
>       <sect3/>
>     </rec>
>     <rec>
>       <sect1/>
>       <sect2/>
>       <sect3/>
>     </rec>
>     <rec>
>       <sect1/>
>       <sect2/>
>       <sect3/>
>     </rec>
>   </lvl>
> </doc>
> 
> The CSV is suppose to look something like:
> 
> col1value,col2value,<rec><sect1/><sect2/><sect3/></rec>
> col1value,col2value,<rec><sect1/><sect2/><sect3/></rec>
> col1value,col2value,<rec><sect1/><sect2/><sect3/></rec>
> 
> The last column contains the textual representation of each 
> of the <rec> nodes in the source document.  Building the CSV 
> structure is simple, but I haven't quite figured out an easy 
> way to convert the <rec> nodes in the tree to their textual 
> representation.  So I have some XSL that looks like:
> 
> <xsl:for-each select="rec">
>   <xsl:variable name="col1" as="xsd:string" 
> select="string('col1value')"/>
>   <xsl:variable name="col2" as="xsd:string" 
> select="string('col2value')"/>
>   <xsl:variable name="col3" as="element()"  select="."/>
>   <xsl:value-of select="concat($col1,$col2,$col3,'&#10;')"/>
> </xsl:for-each>
> 
> Obviously, that variable for col3 doesn't make it happen.  
> Does anyone know of an easy way to do this without writing a 
> recursive template that goes through the entire <rec> node 
> set, which happens to have quite a bit of structure depth 
> under each sect* elements?
> 
> BTW, I do realize that the column values will need to be 
> properly quoted and escaped, but that is an issue I have 
> already solved and left out of the XSL to simplify the 
> explanation of the problem.
> 
> 
> Thanks, Andy.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.