Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Here is the requested generic solution to the problem</strong>:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my" exclude-result-prefixes="my xs"&gt; &lt;xsl:import href="C:/temp/delete/GlobalTypeMappings.xsl"/&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:template match="order_system_a"&gt; &lt;order_system_b&gt; &lt;xsl:apply-templates select="@*"/&gt; &lt;/order_system_b&gt; &lt;/xsl:template&gt; &lt;xsl:template match="order_system_a/@type"&gt; &lt;xsl:attribute name="type" select= "my:convertType('order_system_a', 'order_system_b', .)"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <h2>C:/temp/delete/GlobalTypeMappings.xsl:</h2> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my" exclude-result-prefixes="my xs"&gt; &lt;xsl:key name="kMapFromLocal" match="map" use="concat(@system, '+', @local-type)"/&gt; &lt;xsl:key name="kMapFromValue" match="map" use="concat(@system, '+', @value)"/&gt; &lt;my:TypeMappings&gt; &lt;map system="order_system_a" local-type="1" value="type1"/&gt; &lt;map system="order_system_a" local-type="2" value="type2"/&gt; &lt;map system="order_system_a" local-type="3" value="type3"/&gt; &lt;map system="order_system_a" local-type="4" value="type4"/&gt; &lt;map system="order_system_b" local-type="X" value="type1"/&gt; &lt;map system="order_system_b" local-type="Y" value="type2"/&gt; &lt;map system="order_system_b" local-type="Z" value="type3"/&gt; &lt;map system="order_system_b" local-type="T" value="type4"/&gt; &lt;!-- Other type mappings here --&gt; &lt;/my:TypeMappings&gt; &lt;xsl:function name="my:convertType" as="xs:string?"&gt; &lt;xsl:param name="pfromSystem" as="xs:string"/&gt; &lt;xsl:param name="ptoSystem" as="xs:string"/&gt; &lt;xsl:param name="pfromValue" as="xs:string"/&gt; &lt;xsl:variable name="vthisDoc" select="document('')"/&gt; &lt;xsl:sequence select= "key('kMapFromValue', concat($ptoSystem, '+', key('kMapFromLocal', concat($pfromSystem, '+', $pfromValue), $vthisDoc ) /@value ), $vthisDoc ) /@local-type "/&gt; &lt;/xsl:function&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When the above transformation is applied to the provided XML document</strong>:</p> <pre><code>&lt;order_system_a type="1" /&gt; </code></pre> <p><strong>the wanted, correct result is produced</strong>:</p> <pre><code>&lt;order_system_b type="X"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload