Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to XML transformation 1

Status
Not open for further replies.
Feb 7, 2007
5
US
I am trying to transform a xml file into another xml file.

Specifically:

<magazine>
<magazinename>
<magazinevolume>Mag Volume</magazinevolume>
<magissue>FirstIssue </magissue>
<magcover>"image.gif"</magcover>
<maglink>"page.php?XX"</maglink>
</magazinename>
</magazine>

I need to turn into another xml file:

<cover>
<coverimage picture="<magcover>" link="<maglink>"></coverimage>
...repeat for each <magazinename>...
</cover>

I know how to go from XML to XHTML, but I don't understand how to loop through the elements and turn them into attributes in a different node.


Thank you
 
It is not a terribly good idea to put quotes around the text of node magcover and maglink. You'll see that complicated the transformation, or more so obscuring it without gaining any superiority in the form of construction, rather the contrary. Here is the xslt you can try.
[tt]
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="xml" indent="yes" version="1.0" encoding="utf-8" />
<xsl:template match="/">
<cover>
<xsl:apply-templates select="magazine/magazinename" />
</cover>
</xsl:template>
<xsl:template match="magazinename">
<!-- if the text is quoted as shown -->
<coverimage picture="{translate(magcover,'&#34;','')}" link="{translate(maglink,'&#34;','')}"></coverimage>
[green]<!-- if the text is not quoted, then simply this.
<coverimage picture="(magcover}" link="{maglink}"></coverimage>
-->[/green]
</xsl:template>
</xsl:stylesheet>
[/tt]
 
Thank you! That was perfect. It helped me understand how simple it is. Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top