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 March 8th, 2006, 05:11 AM
Authorized User
 
Join Date: Dec 2005
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\"
 
Old March 8th, 2006, 07:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old March 8th, 2006, 08:04 AM
Authorized User
 
Join Date: Dec 2005
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

 
Old March 8th, 2006, 08:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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





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





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