Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 Display Modes
  #1 (permalink)  
Old July 7th, 2005, 12:46 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT read through XML to transform another XML

Hi all,

Is there any way to write a XSLT that go through the whole xml (element, attribute) then create another xml? (Cannot specific any xml tag name on the xslt)

Thanks!!
Den

XML sample:

<customers>
  <customer>
    <firstname>hello</firstname>
    <lastname>world</lastname>
    <profile_info>
      <profile id="1" number="0" endDate="2005-07-07" />
      <profile id="2" number="0" endDate="2005-07-08" />
      <profile id="3" number="0" endDate="2005-07-09" />
    </profile_info>
  </customer>
</customers>

Reply With Quote
  #2 (permalink)  
Old July 7th, 2005, 01:07 AM
Authorized User
 
Join Date: May 2005
Location: bangalore, karnataka, India.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to meetnaveen4u
Default

Please provide what output.xml u will be looking for. and sample xslt u have tried.

Thanks and Regards
Naveen.
Reply With Quote
  #3 (permalink)  
Old July 7th, 2005, 01:30 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi meetnaveen4u,

The output for now i want to be excatly the same as the sample i given. But in the future, i will add more optional element or attribute in XSLT so when the xml transform to another xml the optional field will exist.

Thanks!

Reply With Quote
  #4 (permalink)  
Old July 7th, 2005, 02:41 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need the identity transform. There's an example of it here:
http://p2p.wrox.com/topic.asp?TOPIC_ID=21082
and it show an element being modified (monkey to new:monkey. You can also remove or add elements.



--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old July 7th, 2005, 03:49 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi joefawcett,

Thank you for your information. That's what i need!!! One more question, after copy the whole original. I added the "optionalField" under the node "unsignedData", i have "Field_1" and "Field_2" under "optionalField". How can i assign the data under those fields? I cannot use <xsl:value-of select"Field_1">, because the variable is not exist in original xml.

THANKS!!!!

My Code:

<-- transform all node from original xml to new xml -->
<xsl:template match="node()|@*"/>
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

<-- add "optionalField" under "unsignedData" node -->
<xsl:template match="unsignedData">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
    <xsl:element name="optionalField">
      <xsl:element name="Field_1"/>
      <xsl:element name="Field_2"/>
    </xsl:element>
  </xsl:copy>
</xsl:template>


Reply With Quote
  #6 (permalink)  
Old July 7th, 2005, 04:23 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got it!!! Thanks for all !!

Reply With Quote
  #7 (permalink)  
Old July 7th, 2005, 06:05 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All,

I got another question. How can i remove one of the element after transform? Let said the element is called "profile_info"?

Thanks!!

XML Code:

<customers>
  <customer>
    <firstname>hello</firstname>
    <lastname>world</lastname>
    <profile_info>
      <profile id="1" number="0" endDate="2005-07-07" />
      <profile id="2" number="0" endDate="2005-07-08" />
      <profile id="3" number="0" endDate="2005-07-09" />
    </profile_info>
  </customer>
</customers>


XSLT Code:

<-- transform all node from original xml to new xml -->
<xsl:template match="node()|@*"/>
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>



Reply With Quote
  #8 (permalink)  
Old July 7th, 2005, 06:21 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Add an empty template that matches "profile_info":
Code:
<xsl:template match="profile_info"/>
Obviously all children will be removed as well.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #9 (permalink)  
Old July 7th, 2005, 09:18 PM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Joe!

You Guyz are PRO!!!!

Reply With Quote
Reply


Thread Tools
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
XML/XSLT Transform Error in ASP kwilliams Classic ASP XML 2 October 9th, 2007 03:26 AM
Transform SQL server 2005 XML with xslt bonekrusher XSLT 0 July 11th, 2007 08:45 PM
Can 1 xslt transform an xml doc into 2 text files Raju Sarode XSLT 7 November 3rd, 2006 04:10 PM
Transform XML with XSLT in JavaScript Mozilla Spankmaster79 Javascript 3 January 18th, 2006 07:31 AM
Transform XML to XML using XSLT Mr.D XSLT 2 September 7th, 2004 03:13 PM



All times are GMT -4. The time now is 09:15 AM.


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