|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Simplify HAIRY xslt
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








