Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2006, 05:11 AM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ramesh.kumarm
Default Loop issue - with n number of same nodes..

My INPUT XML resembles like this:

<?xml version="1.0" encoding="UTF-8"?>
<AddressSearch>
  <utcc:ListOfAddress>
    <utcc:Address>
    <utcc:BA>
      <utcc:OrganisationName>NO1</utcc:OrganisationName>
      <utcc:POBox>POBN1</utcc:POBox>
    </utcc:BA>
    <utcc:AddressReference>
      <utcc:Qualifier>S1</utcc:Qualifier>
    </utcc:AddressReference>
    </utcc:Address>
    <utcc:Address>
    <utcc:BA>
      <utcc:OrganisationName>NO2</utcc:OrganisationName>
      <utcc:POBox>POBN2r</utcc:POBox>
    </utcc:BA>
      <utcc:AddressReference>
      <utcc:RefNum>ARH</utcc:RefNum>
      <utcc:Qualifier>G</utcc:Qualifier>
      <utcc:DistrictCode>DC</utcc:DistrictCode>
    </utcc:AddressReference>
    </utcc:Address>
  </utcc:ListOfAddress>
</AddressSearch>

Now, I need to transform this xml so that my output resembles something like this:

<?xml version="1.0" encoding="UTF-8"?>
<payload>
  <utcc:OrganisationName(1)>NO1</utcc:OrganisationName(1)>
  <utcc:POBox(1)>POBN1</utcc:POBox(1)></utcc:BA>
  <utcc:AddressReference(1)>
    <utcc:Qualifier(1)>S1</utcc:Qualifier(1)>
  </utcc:AddressReference(1)>
  <utcc:OrganisationName(2)>NO2</utcc:OrganisationName(2)>
  <utcc:POBox(2)>POBN2r</utcc:POBox(2)>
  <utcc:AddressReference(2)>
    <utcc:RefNum>ARH</utcc:RefNum(2)>
    <utcc:Qualifier(2)>G</utcc:Qualifier(2)>
    <utcc:DistrictCode(2)>DC</utcc:DistrictCode(2)>
  </utcc:AddressReference(2)>
</payload>

How can v substitute (n) in this? Is this possible?
I know we need to write a loop to exzecute the same. But i'm not sure how to get this work just fine.
Does anyone have a template for this?

__________________
Ramesh
\"Always Look For Something NEW\"
Reply With Quote
  #2 (permalink)  
Old March 8th, 2006, 07:55 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your output is not well-formed XML, so you can't construct it using XSLT.

Instead of

<utcc:OrganisationName(1)>NO1</utcc:OrganisationName(1)>

why not go for

<utcc:OrganisationName seq="1">NO1</utcc:OrganisationName>

This can be achieved very easily using position() or xsl:number.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old March 8th, 2006, 08:04 AM
Authorized User
 
Join Date: Dec 2005
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ramesh.kumarm
Default

Thanx for the reply mike!
But my requirement is like this only. The thing is - i need to finally convert the above mentioned output xml to a TLV string which should possess the following format (n).

SO even if the xml is not well-formed....cant we create one?

kindly advice!

ramesh

Reply With Quote
  #4 (permalink)  
Old March 8th, 2006, 08:19 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can serialize the output of an XML transformation as text rather than as XML, but then you have to generate the pseudo-tags yourself, for example writing &lt;somename (1)&gt; etc.

It seems a very odd thing to do. XML is flexible enough for your needs, why use something that isn't XML?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
for-each loop predefined number of times vonkeldoos XSLT 1 February 22nd, 2007 07:47 AM
count the number of nodes in an XML doc crmpicco Perl 3 December 8th, 2006 08:30 AM
Page Number Issue dingarim XSLT 0 August 22nd, 2006 02:23 PM
Nested Loop Select Box Issue mat41 Classic ASP Basics 5 August 24th, 2004 11:02 PM
How to count total number of nodes in an xml file? nimesh XSLT 1 August 12th, 2004 03:26 AM



All times are GMT -4. The time now is 07:25 AM.


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