 |
| 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
|
|
|
|

July 6th, 2005, 11:46 PM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

July 7th, 2005, 12:07 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Please provide what output.xml u will be looking for. and sample xslt u have tried.
Thanks and Regards
Naveen.
|
|

July 7th, 2005, 12:30 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

July 7th, 2005, 01:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

July 7th, 2005, 02:49 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

July 7th, 2005, 03:23 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I got it!!! Thanks for all !!
|
|

July 7th, 2005, 05:05 AM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

July 7th, 2005, 05:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

July 7th, 2005, 08:18 PM
|
|
Registered User
|
|
Join Date: Jul 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Joe!
You Guyz are PRO!!!!
|
|
 |