|
-
Jun 23rd, 2010, 08:28 AM
#1
[RESOLVED] Applying XSL Transformation!
I have a well formed XML that I need to modify.
My input file looks like this.
Code:
<?xml version="1.0"?>
<Root>
<VOBaseCollection>
<VOUploadPackage>
<VOPartyContainer>
...blah
</VOPartyContainer>
</VOUploadPackage>
<VOPartyContainer>
...blah
</VOPartyContainer>
<VOUploadPackage>
...blah
</VOUploadPackage>
</VOBaseCollection>
</Root>
I used a XSL transformation to get my desired output, but it came with a slightly different output file.
This is my XSL transformation.
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<Root BatchUploadType="Party">
<VOUploadBatch>
<UploadPackages>
<VOBaseCollection>
<VOUploadPackage>
<xsl:apply-templates select="Root/VOBaseCollection/VOUploadPackage/VOPartyContainer" />
</VOUploadPackage>
</VOBaseCollection>
</UploadPackages>
</VOUploadBatch>
</Root>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
My desired output should like this.
Code:
<?xml version="1.0"?>
<Root BatchUploadType="Party">
<VOUploadBatch>
<UploadPackages>
<VOBaseCollection>
<VOUploadPackage>
<VOPartyContainer>
blah
</VOPartyContainer>
</VOUploadPackage>
<VOUploadPackage>
<VOPartyContainer>
blah
</VOPartyContainer>
</VOUploadPackage>
</VOBaseCollection>
</UploadPackages>
</VOUploadBatch>
</Root>
However after applying the transformation, it looks like this.
Code:
<?xml version="1.0"?>
<Root BatchUploadType="Party">
<VOUploadBatch>
<UploadPackages>
<VOBaseCollection>
<VOUploadPackage>
<VOPartyContainer>
</VOPartyContainer>
<VOPartyContainer>
</VOPartyContainer>
</VOUploadPackage>
</VOBaseCollection>
</UploadPackages>
</VOUploadBatch>
</Root>
What changes do I need to make in my XSL to get it transformed correctly?
I do not wish to lose the <VOUploadBatch> tag
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jun 23rd, 2010, 03:36 PM
#2
Re: Applying XSL Transformation!
I'm not great with XSL, but could you use something like this instead...?
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<Root BatchUploadType="Party">
<VOUploadBatch>
<UploadPackages>
<VOBaseCollection>
<xsl:for-each select="Root/VOBaseCollection/*">
<VOUploadPackage>
<VOPartyContainer>
<xsl:value-of select="."/>
</VOPartyContainer>
</VOUploadPackage>
</xsl:for-each>
</VOBaseCollection>
</UploadPackages>
</VOUploadBatch>
</Root>
</xsl:template>
</xsl:stylesheet>
Using your input XML, it outputs:
Code:
<Root BatchUploadType="Party">
<VOUploadBatch>
<UploadPackages>
<VOBaseCollection>
<VOUploadPackage>
<VOPartyContainer>
...blah
</VOPartyContainer>
</VOUploadPackage>
<VOUploadPackage>
<VOPartyContainer>
...blah
</VOPartyContainer>
</VOUploadPackage>
<VOUploadPackage>
<VOPartyContainer>
...blah
</VOPartyContainer>
</VOUploadPackage>
</VOBaseCollection>
</UploadPackages>
</VOUploadBatch>
</Root>
-
Jun 24th, 2010, 09:55 AM
#3
Re: Applying XSL Transformation!
SambaNeko,
Thank you for responding to my thread. I will have to try that out.
I am n00b when it comes to all the XML stuff.
I did a string concatenation to get the correct output. That is not only time consuming, but also dangerous.
I will give this approach a shot.
Thanks Again!
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jun 24th, 2010, 04:38 PM
#4
Re: Applying XSL Transformation!
Using; <xsl:value-of select="." />
You can also use; <xsl;values-of select="text()" />
The xsl:copy recreates the element and all of its children.
-
Jun 26th, 2010, 09:36 AM
#5
Re: Applying XSL Transformation!
Is there some way to make the select = text() put in tags.
Right now, the "blah" in my initial xml represents another xml structure. I do not wish to disturb this.
If I use Samba's XSLT, the xml structure gets output as text (without the tags).
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jun 26th, 2010, 05:35 PM
#6
Re: Applying XSL Transformation!
Use the transformation you had originally then.
-
Jun 26th, 2010, 05:59 PM
#7
Re: Applying XSL Transformation!
Apologies; I now notice the subtle difference between the two formats What you had originally is on the right track, however your original XPath selection is too specific. You appear to need a <VOUploadPackage> for each <VOPartyContainer> and VoPartyContainers can be a child element of VOUploadPackage or VOBaseCollection.
With that in mind you need to us "//" to select any "VOpartyContainer" which is any where in the VOBaseCollection hierarchy then output the VOUploadPackage in a template for VOPartyContainers. You will also need to use xsl:copy-of to make a deep copy of the element instead of the "catch-all" template you originally had.
See below;
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<Root BatchUploadType="Party">
<VOUploadBatch>
<UploadPackages>
<VOBaseCollection>
<xsl:apply-templates select="Root/VOBaseCollection//VOPartyContainer" />
</VOBaseCollection>
</UploadPackages>
</VOUploadBatch>
</Root>
</xsl:template>
<xsl:template match="VOPartyContainer">
<VOUploadPackage>
<xsl:copy-of select="." />
</VOUploadPackage>
</xsl:template>
</xsl:stylesheet>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|