|
next
|
 Subject: Pulling Elements While Keeping the Parentage Author: James Durning Date: 08 Dec 2006 11:06 AM
|
1. Instead of rewriting your schema element,
<xs:schema targetNamespace="http://partner2learn.com/MigrationPack/Structure" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://partner2learn.com/MigrationPack/Structure"
.../>
if it is not going to change, for cleanliness you could use
<xsl:copy>
<xsl:copy-of select="@*"/>
...
</xsl:copy>
2. Use templates and apply-templates.
eg. instead of
<xsl:for-each select="xs:element[@xml='yes']">
Use something like
<xsl:apply-templates select="xs:element[@xml='yes']"/>
and have a template
<xsl:template match="xs:element"> ...
3. Simplification example: A lot of the simplification depends on knowing the outerlying structure of the schema. If an element has child nodes, the structure is like:
<xs:element>
<xs:complexType>
<xs:group|all|sequence|choice>
<xs:element>
So we can reduce something like:
<xsl:for-each select="descendant::xs:element[@att='yes'][1]">
<xsl:if test="substring-before(substring-after(@name,'_'),'_')=$d1s0">
<xs:attribute name="{substring-before(@name,'_')}"/>
<xsl:for-each select="following-sibling::xs:element[@att='yes']">
<xs:attribute name="{substring-before(@name,'_')}"/>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
to: (note this assumes you are not skipping levels between nodes with @att='yes')
<xsl:if test="substring-before(substring-after(xs:complexType/*/xs:element[@att='yes'][1]/@name,'_'),'_')=$d1s0">
<xsl:for-each select="xs:complexType/*/xs:element[@att='yes']">
<xs:attribute name="{substring-before(@name,'_')}"/>
</xsl:for-each>
</xsl:if>
Ultimately, it's hard to suggest more without more background information.
|
next
|
 Subject: Pulling Elements While Keeping the Parentage Author: Barry DeBruin Date: 09 Dec 2006 10:18 PM
|
Jame,
Thanks for the copy attributes... much cleaner.
Will a template work in the scenario below:
<xsl:for-each select="descendant::xs:element[@xml='yes'][1]">
<xs:element name="{substring-before(@name,'_Element')}">
<xsl:for-each select="descendant::xs:element[@xml='yes'][1]">
<xs:element name="{substring-before(@name,'_Element')}">
<xsl:for-each select="descendant::xs:element[@xml='yes'][1]">
<xs:element name="{substring-before(@name,'_Element')}">
<xsl:for-each select="descendant::xs:element[@xml='yes'][1]">
<xs:element name="{substring-before(@name,'_Element')}">
<xsl:for-each select="descendant::xs:element[@xml='yes'][1]">
<xs:element name="{substring-before(@name,'_Element')}">
</xs:element>
<xsl:for-each select="following-sibling::xs:element[@xml='yes']">
<xs:element name="{substring-before(@name,'_Element')}"></xs:element>
</xsl:for-each>
<!--Paste above and below here infinitely-->
</xsl:for-each>
</xs:element>
<xsl:for-each select="following-sibling::xs:element[@xml='yes']">
<xs:element name="{substring-before(@name,'_Element')}"></xs:element>
</xsl:for-each>
<!-- and here infinitely-->
</xsl:for-each>
</xs:element>
<xsl:for-each select="following-sibling::xs:element[@xml='yes']">
<xs:element name="{substring-before(@name,'_Element')}"></xs:element>
</xsl:for-each>
<!-- and here infinitely-->
</xsl:for-each>
</xs:element>
<xsl:for-each select="following-sibling::xs:element[@xml='yes']">
<xs:element name="{substring-before(@name,'_Element')}"></xs:element>
</xsl:for-each>
<!-- and here infinitely-->
</xsl:for-each>
|
|
|
|