Вот запрашиваемое общее решение проблемы :
<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">
<xsl:import href="C:/temp/delete/GlobalTypeMappings.xsl"/>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="order_system_a">
<order_system_b>
<xsl:apply-templates select="@*"/>
</order_system_b>
</xsl:template>
<xsl:template match="order_system_a/@type">
<xsl:attribute name="type" select=
"my:convertType('order_system_a', 'order_system_b', .)"/>
</xsl:template>
</xsl:stylesheet>
C: /temp/delete/GlobalTypeMappings.xsl:
<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">
<xsl:key name="kMapFromLocal" match="map"
use="concat(@system, '+', @local-type)"/>
<xsl:key name="kMapFromValue" match="map"
use="concat(@system, '+', @value)"/>
<my:TypeMappings>
<map system="order_system_a" local-type="1" value="type1"/>
<map system="order_system_a" local-type="2" value="type2"/>
<map system="order_system_a" local-type="3" value="type3"/>
<map system="order_system_a" local-type="4" value="type4"/>
<map system="order_system_b" local-type="X" value="type1"/>
<map system="order_system_b" local-type="Y" value="type2"/>
<map system="order_system_b" local-type="Z" value="type3"/>
<map system="order_system_b" local-type="T" value="type4"/>
<!-- Other type mappings here -->
</my:TypeMappings>
<xsl:function name="my:convertType" as="xs:string?">
<xsl:param name="pfromSystem" as="xs:string"/>
<xsl:param name="ptoSystem" as="xs:string"/>
<xsl:param name="pfromValue" as="xs:string"/>
<xsl:variable name="vthisDoc" select="document('')"/>
<xsl:sequence select=
"key('kMapFromValue',
concat($ptoSystem,
'+',
key('kMapFromLocal',
concat($pfromSystem, '+', $pfromValue),
$vthisDoc
)
/@value
),
$vthisDoc
)
/@local-type
"/>
</xsl:function>
</xsl:stylesheet>
Когда вышеуказанное преобразование применяется к предоставленному документу XML :
<order_system_a type="1" />
желаемый, правильный результат получается :
<order_system_b type="X"/>