I am trying to generate an output XML file from a master xml file (Input1) based on data available in a decision xml file (Input2).
Master file
<Level1>
<Level2>
<LinkedTo>DATA1</LinkedTo> <!DATA1 in the decision file>
<Attribute1>1</Attribute1>
<Attribute2>2</Attribute2>
</Level2>
<Level2>
<LinkedTo>DATA2</LinkedTo>
<Attribute1>3</Attribute1>
<Attribute2>4</Attribute2>
</Level2>
</Level1>
Decision File:
<TopLevel>
<DATA1>
<Available>Y</Available>
</DATA1>
<DATA2>
<Available>N</Available>
</DATA2>
</TopLevel>
The XSLT when processed must output resultant file (Based on a YES or a NO in the decision file).
<Level1>
<Level2>
<Attribute1>1</Attribute1>
<Attribute2>2</Attribute2>
</Level2>
</Level1>
I must confess I have never done XML stuff before, but this is needed for a feasibility study. What should be in the XSLT? I can use your answers and extend the concept.
Or if there is an alternative (python,C#,C,C++ etc), those are welcome as well. I can manage with C/C++ or any procedure oriented language.
Use document
function. Pass URI to decision XML, e.g.:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Level1">
<xsl:copy>
<xsl:apply-templates select="Level2"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Level2">
<xsl:if test="document('Decision.xml')/TopLevel/*[
name() = current()/LinkedTo and Available = 'Y']">
<xsl:copy>
<xsl:apply-templates select="*[not(self::LinkedTo)]"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="*">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With