[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Simplify HAIRY xslt

Subject: Simplify HAIRY xslt
From: Marcus Andersson <marcus@xxxxxxxxxx>
Date: Fri, 14 May 2004 02:35:19 +0200
extremely hairy
I have this stylesheet that generates another stylesheet based on some XML that contains some XPaths that should get evaluated on the next pass and also generate some other stuff like absolute XPaths. The code I have works but is extremely hairy and also duplicates some code.

I provide the template that does the duplication in hope that someone can help me. The structures inside the res:when and the res:otherwise are identical apart from the content of the uid attribute. I'll be glad to provide you with more info if you need.

  <xsl:template name="rule">
    <xsl:param name="uri"/>
    <xsl:variable name="prefix" select="../@prefix"/>

<res:choose>
<res:when test="*[name() = '{$prefix}:rule']">
<xsl:element name="{$prefix}:rule" namespace="{$uri}">
<xsl:if test="string(@display)">
<xsl:attribute name="displayValue">{<xsl:value-of select="@display"/>}</xsl:attribute>
</xsl:if>
<xsl:attribute name="uid">{*[name() = '<xsl:value-of select="$prefix"/>:rule']/@uid}</xsl:attribute>
<xsl:attribute name="xpath">{$newXpath}</xsl:attribute>
<xsl:attribute name="type">{$type}</xsl:attribute>
<xsl:copy-of select="@*|node()"/>
</xsl:element>
</res:when>
<res:otherwise>
<xsl:element name="{$prefix}:rule" namespace="{$uri}">
<xsl:if test="string(@display)">
<xsl:attribute name="displayValue">{<xsl:value-of select="@display"/>}</xsl:attribute>
</xsl:if>
<xsl:attribute name="uid">{generate-id()}_<xsl:value-of select="$prefix"/></xsl:attribute>
<xsl:attribute name="xpath">{$newXpath}</xsl:attribute>
<xsl:attribute name="type">{$type}</xsl:attribute>
<xsl:copy-of select="@*|node()"/>
</xsl:element>
</res:otherwise>
</res:choose>


</xsl:template>

Sorry about the long lines.

Thanks

/Marcus

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.