I am writing a transformation to "flatten" the xml schema and for this purpose I am copying the referenced elements (for now only by attribute type on elements). The transformation itself "is working" as can be seen below. However when I try to use the select
select="//node()[./@name = $localname]"
in variable, the variable is not correctly set and oxygen XML Editor shows it in debug as empty, and it looks like the error is in the definition of variable $localname, however I do not know what it is concrectly :( When I use the select this way:
select="//node()[./@name = 'someRealValue']"
Then the variable is set up correctly, and on the output is nothing changed.
Can anybody suggest solution or what's wrong with the variable or xpath? Thanks in advance!
I have this input xml (shortened)
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://ift.tt/tphNwY"
xmlns:tst="http://www.test1.test"
targetNamespace="http://www.test1.test"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<simpleType name="ClaimCategoryId">
<restriction base="string"/>
</simpleType>
<simpleType name="StatusCategoryId">
<restriction base="string"/>
</simpleType>
<complexType name="StatusCategory">
<sequence>
<element name="statusCategoryId" type="tst:StatusCategoryId"/>
<element name="nameEN" type="string"/>
<element name="nameCZ" type="string"/>
<element name="claimCategoryId" type="tst:ClaimCategoryId"/>
</sequence>
</complexType>
<complexType name="StatusCategoryCollection">
<sequence>
<element name="statusCategoryInstance" type="tst:StatusCategory"
minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</schema>
And this transformation:
<xsl:function name="pk:childsHasType">
<xsl:param name="this"/>
<xsl:variable name="testX" select="substring-before($this/@type,':')"/>
<xsl:choose>
<xsl:when test="$this/*">
<xsl:for-each select="$this/*">
<xsl:value-of select="concat($testX != $var/namespace[ns=$defaultSchemaNS]/prefix,string-join(pk:childsHasType(.),'|'))"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$testX != $var/namespace[ns=$defaultSchemaNS]/prefix"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:variable name="defaultSchemaNS" select="'http://ift.tt/tphNwY'"/>
<xsl:template match="xs:element">
<xsl:variable name="test" select="substring-before(@type,':')"/>
<xsl:variable name="differentTypeTest" select="string-join(pk:childsHasType(.), ', ')"/>
<xsl:choose>
<xsl:when test="contains($differentTypeTest,'true')">
<xsl:variable name="localname" select="substring-after(@type,':')"/>
<xsl:element name="element" namespace="{$var/namespace[prefix=$test]/ns}">
<xsl:copy-of select="@*[name()!='type']"/>
<xsl:text> </xsl:text>
<xsl:copy-of select="//node()[./@name = $localname]"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="child::node()"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="xs:complexType">
<xsl:variable name="test" select="substring-before(@type,':')"/>
<xsl:variable name="differentTypeTest" select="string-join(pk:childsHasType(.), ', ')"/>
<xsl:choose>
<xsl:when test="contains($differentTypeTest,'true')">
<xsl:variable name="localname" select="substring-after(@type,':')"/>
<xsl:element name="complexType" namespace="{$var/namespace[prefix=$test]/ns}">
<xsl:copy-of select="@*[name()!='type']"/>
<xsl:text> </xsl:text>
<xsl:copy-of select="//node()[./@name = $localname]"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="child::node()"/>
<!--<xsl:copy-of select="child::*"/>-->
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
And this is the output
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://ift.tt/tphNwY">
<complexType name="StatusCategory">
<element xmlns="http://ift.tt/1lrf87m" name="statusCategoryId">
<simpleType xmlns="http://ift.tt/tphNwY" xmlns:rturdt="http://ift.tt/1lrf87m" name="StatusCategoryId">
<restriction base="string"/>
</simpleType>
</element>
<element xmlns:rturdt="http://ift.tt/1lrf87m" name="nameEN" type="string"/>
<element xmlns:rturdt="http://ift.tt/1lrf87m" name="nameCZ" type="string"/>
<element xmlns="http://ift.tt/1lrf87m" name="claimCategoryId">
<simpleType xmlns="http://ift.tt/tphNwY" xmlns:rturdt="http://ift.tt/1lrf87m" name="ClaimCategoryId">
<restriction base="string"/>
</simpleType>
</element>
</complexType>
<complexType name="StatusCategoryCollection">
<element xmlns="http://ift.tt/1lrf87m" name="statusCategoryInstance" minOccurs="0" maxOccurs="unbounded">
<complexType xmlns="http://ift.tt/tphNwY" xmlns:rturdt="http://ift.tt/1lrf87m" name="StatusCategory">
<sequence>
<element name="statusCategoryId" type="rturdt:StatusCategoryId"/>
<element name="nameEN" type="string"/>
<element name="nameCZ" type="string"/>
<element name="claimCategoryId" type="rturdt:ClaimCategoryId"/>
</sequence>
</complexType>
</element>
</complexType>
</schema>
No comments:
Post a Comment