How to use XSLT to transform XML according to the data in another XML

A

ai2003lian

I have a XML containing more information than required. And I want to
transform it to a XML with less information according to the
requirement data in another XML. How could I accomplish this using
XSLT?

Here're the XML files:

source.xml :

<AllFields>
<field name="f1", type="N">value1</field>
<field name="f2", type="N">value2</field>
<field name="f3", type="N">value3</field>
<field name="f4", type="N">value4</field>

....
</AllFields>

requirement.xml :

<requiredFields>
<field>f1</field>
<field>f3</field>
</requiredFields>

result.xml :

<AllFields>
<field name="f1", type="N">value1</field>
<field name="f3", type="N">value3</field>
</AllFields>

Thanks in advance!
 
J

Joris Gillis

Tempore 17:58:33 said:
I have a XML containing more information than required. And I want to
transform it to a XML with less information according to the
requirement data in another XML. How could I accomplish this using
XSLT?
Hi,


Here's one approach:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="AllFields">
<xsl:copy>
<xsl:copy-of select="field[@name=document('requirement.xml')/*/field]"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>


regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top