Hi All,
i am have some XML that is lay out as follows;
Code:
<drivers>
<driver2licence>A</driver2licence>
<driver3licence>I</driver3licence>
<driver4licence>E</driver4licence>
<drivers>
Each value needs to be mapped to a different value, at different points in the output xml, i am thinking a function that i can call from that will look up and check the correct mapping each time, i have NEVER used a function before, so i am a little lost;
the function (in my understanding) i can call this function and tell it where its "root is" and it will look there (.) and check the relevant mappings and return a value.
Code:
<xsl:function name="licence" as="xs:string">
<xsl:choose>
<xsl:when test=". = 'A'">F</xsl:when>
<xsl:when test=". = 'I'">N</xsl:when>
<xsl:when test=". = 'E'">M</xsl:when>
<xsl:otherwise>Z</xsl:otherwise>
</xsl:choose>
</xsl:function>
then to call this function driver 2,3,4 would be as follows
Code:
<Driver2>
<licence>
<xsl:apply-templates select="$simple/driver2licence[licence(.)]"/>
</licence>
</Driver2>
<Driver3>
<licence>
<xsl:apply-templates select="$simple/driver3licence[licence(.)]"/>
</licence>
</Driver3>
The main problem is between /driver2 and <driver3> there will be another 15-20 nodes that access different data.
Can you please modify, or throw and away and re-write how i would go about this? I hope the code provided helps explain what i want.
The reason i want this is currently i have 20 fields under each Parent Driver node, and it is just chunks and chunks of repeated code, which when i need to change a value, i have to change 5-25 times for each driver and each scenario. understanding how to use a function to use 1 set of mappings for various fields will allow me drastically reduce the transform i am writting.