I’m trying since this morning to add value in a xml file using xslt. So basically i have this xml file 1.xml
<?xml version="1.0" encoding="UTF-8"?>
<Orderfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<order>
<establishmenthour>10:38:00</ establishmenthour>
<ExpirationDate/>
<acc/>
<identification>170610009-01</identification>
</order>
<order>
<establishmenthour>10:40:00</ establishmenthour>
<ExpirationDate/>
<acc/>
<identification>170610910-03</identification>
</order>
<order>
<establishmenthour>10:42:00</ establishmenthour>
<ExpirationDate/>
<acc/>
<identification>170610015-01</identification>
</order>
And I have these informations from a second xml file called 2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Orderfile>
<order>
<identification>170610009-01</identification>
<ExpirationDate>2017-06-21</ExpirationDate>
</order>
<order>
<identification>170610015-01</identification>
<ExpirationDate>2017-02-22</ExpirationDate>
</order>
<order>
<identification>170610024-01</identification>
<ExpirationDate>2017-08-02</ExpirationDate>
</order>
</Orderfile>
And I would like to have that --> merged.xml
<?xml version="1.0" encoding="UTF-8"?>
<Orderfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<order>
<establishmenthour>10:38:00</establishmenthour>
<ExpirationDate>2017-06-21</ExpirationDate/>
<acc/>
<identification>170610009-01</identification>
</order>
<order>
<establishmenthour>10:40:00</ establishmenthour>
<ExpirationDate/>
<acc/>
<identification>170610910-03</identification>
</order>
<order>
<establishmenthour>10:42:00</ establishmenthour>
<ExpirationDate>2017-02-22</ExpirationDate/>
<acc/>
<identification>170610015-01</identification>
</order>
I would like to read the texte file and for any « id » that match to the xml file i twill add the expiration date.
This is what I tried :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="version">
<xsl:copy>
<xsl:apply-templates select="*"/>
<xsl:apply-templates select="document('2.xml')/Orderfile/order/*" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But that’s not working can you please help me.
documentfunction to access other files, but the file would need to be XML. It would also be easier to match up the ids if it were XML.id(170610009-01)is computing170610009minus01and then callin theidfunction on the result so that is nonsense. Furthermore theidfunction works only with a DTD definingIDattributes. In general you are better off moving to XSLT 2.0 where you can useunparsed-textto read in a text file, use regular expressions withtokenizeand/orxsl:analyze-stringand then you would match on the data as necessary.