Altova Mailing List Archives>Archive Index >xsl-list Archive Home >Recent entries >Thread Prev - [xsl] Converting a node tree to a textual representation [Thread Next] RE: [xsl] Converting a node tree to a textual representationTo: Date: 9/3/2006 6:16:00 AM If you're using Saxon you could use saxon:serialize(). Or you could use Evan Lenz's serializer implemented in XSLT: www.---.com 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: [xsl] 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,' ')"/> > </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. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
