Programmer's Challenge Solved

  • Mar. 7th, 2007 at 7:18 PM
geek, smart, geeky girl
Remember this?


Remember the xml code? Dave ,[info]csixty4, suggested some for-each statements. I played around with it for a few hours and was finally able to grab the pattern and output I desired. I'll share the results for any google surfers!

Here it is sample.xml:

sample.xml )

Here is the Transformation XSLT sample.xsl

sample.xsl )

Here is the output file sample.txt

sample.txt )

Programmer's Challenge

  • Mar. 6th, 2007 at 10:59 PM
chester cat crazy luny
I've been having to do an XML project at work and I was wondering if anyone else who reads this has had experience in transforming xml using XSLT stylesheets to transform xml into plain text.
I've had success in such simple elements in xml format, but am stuck again when the file is more complicatied such as:

<parent>



<child1>

<tag>value</tag>

<tag>value</tag>



<grandchild1>

<tag>value</tag>

<tag>value</tag>

</grandchild>



<grandchild2>

<tag>value</tag>

<tag>value</tag>

</grandchild>

</child1>



<child2>

<tag>value</tag>

<tag>value</tag>



<grandchild3>

<tag>value</tag>

<tag>value</tag>

</grandchild>



<grandchild4>

<tag>value</tag>

<tag>value</tag>

</grandchild>

</child2>

.....

</parent>


*Note the tag elements are different names, but this pattern is repeatedly defined, of course.

So I want it to look like this

  • child1_tag child1_tag grandchild1_tag grand_child1_tag

  • child1_tag child1_tag grandchild2_tag grand_child2_tag

  • child2_tag child2_tag grandchild3_tag grand_child3_tag

  • child2_tag child2_tag grandchild4_tag grand_child4_tag

  • .......



as a plain text output , deliminted by a special character such as | . (note the bullets are not output!). I don't want the tags themselves to be output, only the values