Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 17th, 2005, 07:21 AM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML to Txt using XSLT - Help


Hi all,

    I have an xml file...

    <xml version="1.0">
    <Sample>
        <Data ref="#strt1">This is Data</Data>

        <Start refer="strt1" childref="#traverse1">This is to traverse1</Start>
        <Start refer="strt2" childref="#traverse2">This is to traverse2</Start>
        <Start refer="strt3" childref="#traverse3">This is to traverse3</Start>

        <End id="traverse1" name="Final"> This is the End</End>
        <End id="traverse2" name="Final Text"> This is the End</End>

    </Sample>

I need to parse it this way...

1. Get the value of the attribute "ref" for the element "Data" i.e. '#strt1"

2. Remove the symbol "#" i.e. "strt1"

3. Get the value of attribute "childref" for the element Start whose "refer" attribute value matches "strt1" i.e. "#traverse1"

4. Get the value of attribute "name" for the element End whose "id" attribute value matches "traverse1" i.e. "Final".


How can I do this??? Plz help. This is urgent.
 
Old October 17th, 2005, 07:43 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I usually don't reply when people say the problem is urgent, because I prefer giving answers if I think people will have time to study them properly. But I'll make an exception.

1. Data/@ref

2. translate(Data/@ref, '#', '')

3. key('Start', translate(Data/@ref, '#', '')) where you have defined

<xsl:key name="Start" match="Start" use="@refer"/>

4. This just repeats steps 2 and 3 so you already know how to do it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 17th, 2005, 11:28 PM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx a lot Michael

I have another problem... If there are multiple values for any attribute, how do I do this??

The scenario is like this

        <Start refer="strt1" childref="#traverse1 #traverse2">Traverse</Start>

        <End id="traverse1" name="Final"> This is the End</End>
        <End id="traverse2" name="Final Text"> This is the End</End>
        <End id="traverse3" name="End"> End</End>

Plz help...
 
Old October 18th, 2005, 02:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XPath 2.0 has a built-in function tokenize() to split the attribute value into a sequence of tokens. If you're stuck with 1.0, there's an XSLT template str:tokenize at www.exslt.org that you can copy into your stylesheet (use the template rather than the extension function for portability).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 19th, 2005, 12:30 AM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx a lot...

Everything works fine if tested seperately. But combined, it doesnt serve my purpose. My actual need is I have an xml file like this:

<xml version="1.0">
    <Sample>
        <Data ref="#strt1">This is Data</Data>

        <Start refer="strt1" anotherRef="#another" childref="#traverse1 #traverse2">This is to traverse</Start>
        <Start refer="strt2" childref="#traverse3">This is to traverse</Start>

        <Another id="another" endRef="#end1" name="Final"> This is another Traversal</Another>

        <Mid id="traverse1" endRef="#end1" name="Final"> This is the Traversal1</Mid>
        <Mid id="traverse2" endRef="#end2" name="Final Text"> This is the Traversal2</Mid>
        <Mid id="traverse3" endRef="#end3" name="End"> This is the Traversal3</Mid>

        <End id="end1" name="Final"> This is the End1</End>
        <End id="end2" name="Final Text"> This is the End2</End>
        <End id="end3" name="End"> This is the End3</End>

    </Sample>

The output should be a txt file like this:

This is another Traversal,This is the Traversal1,This is the End1
This is another Traversal,This is the Traversal2,This is the End2

The logic of traversing the data is the same as mentioned earlier...

Need comments plz...







Similar Threads
Thread Thread Starter Forum Replies Last Post
How to output dataset to .txt file not to .xml? nesrine C# 1 March 8th, 2007 11:34 AM
How to output dataset to .txt file not to .xml? nesrine ASP.NET 2.0 Professional 0 March 8th, 2007 05:36 AM
xml validation of entity text in txt files reblev XML 1 May 4th, 2006 09:03 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
XSLT for complicated xml to xml transf. required doug@sirvisetti XSLT 3 June 17th, 2005 04:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.