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

use generate-id and keys to make a transform more eff

Subject: use generate-id and keys to make a transform more efficient
From: "Mangrove Jack" <mangrovejack@xxxxxx>
Date: Wed, 07 Mar 2012 00:57:50 -0500
 use generate-id and keys to make a transform more  eff
Hi,

I have the following that I'm currently working on and am sure that it can be improved upon. B I've got Michael Kay's book and have been through Dave Pawson's site many times, but can't figure our how to apply their advice to my specific tranform.

Anyway, I'm limited to pure XSLT (no extension functions), v1.0 only. B No option to change the input xml nor upgrade to XSLT v2.0 either unfortunately.

Here are the contents of my files:

input.xml:
<entries>
 B <entry>
 B  B <qqqq>
 B  B  B <id>1111</id>
 B  B </qqqq>
 B </entry>
 B <entry>
 B  B <startLoop>
 B  B  B <loopId>1</loopId>
 B  B </startLoop>
 B </entry>
 B <entry>
 B  B <qqqq>
 B  B  B <id>2222</id>
 B  B </qqqq>
 B </entry>
 B <entry>
 B  B <endLoop>
 B  B  B <loopId>1</loopId>
 B  B </endLoop>
 B </entry>
 B <entry>
 B  B <qqqq>
 B  B  B <id>3333</id>
 B  B </qqqq>
 B </entry>
 B <entry>
 B  B <startLoop>
 B  B  B <loopId>2</loopId>
 B  B </startLoop>
 B </entry>
 B <entry>
 B  B <endLoop>
 B  B  B <loopId>2</loopId>
 B  B </endLoop>
 B </entry>
 B <entry>
 B  B <qqqq>
 B  B  B <id>4444</id>
 B  B </qqqq>
 B </entry>
</entries>


output.xml:
<AAA>
 B <SEQUENCE>
 B  B <outputEntry>
 B  B  B <entry>
 B  B  B  B <qqqq>
 B  B  B  B  B <id>1111</id>
 B  B  B  B </qqqq>
 B  B  B </entry>
 B  B </outputEntry>
 B  B <outputEntry>
 B  B  B <entry>
 B  B  B  B <startLoop>
 B  B  B  B  B <loopId>1</loopId>
 B  B  B  B </startLoop>
 B  B  B </entry>
 B  B </outputEntry>
 B  B <outputEntry>
 B  B  B <entry>
 B  B  B  B <qqqq>
 B  B  B  B  B <id>3333</id>
 B  B  B  B </qqqq>
 B  B  B </entry>
 B  B </outputEntry>
 B  B <outputEntry>
 B  B  B <entry>
 B  B  B  B <startLoop>
 B  B  B  B  B <loopId>2</loopId>
 B  B  B  B </startLoop>
 B  B  B </entry>
 B  B </outputEntry>
 B  B <outputEntry>
 B  B  B <entry>
 B  B  B  B <qqqq>
 B  B  B  B  B <id>4444</id>
 B  B  B  B </qqqq>
 B  B  B </entry>
 B  B </outputEntry>
 B </SEQUENCE>

 B <LOOPS>
 B  B <LOOP>
 B  B  B <STARTLOOP>
 B  B  B  B <entry>
 B  B  B  B  B <startLoop>
 B  B  B  B  B  B <loopId>1</loopId>
 B  B  B  B  B </startLoop>
 B  B  B  B </entry>
 B  B  B </STARTLOOP>
 B  B  B <MIDDLE>
 B  B  B  B <entry>
 B  B  B  B  B <qqqq>
 B  B  B  B  B  B <id>2222</id>
 B  B  B  B  B </qqqq>
 B  B  B  B </entry>
 B  B  B </MIDDLE>
 B  B  B <ENDLOOP>
 B  B  B  B <entry>
 B  B  B  B  B <endLoop>
 B  B  B  B  B  B <loopId>1</loopId>
 B  B  B  B  B </endLoop>
 B  B  B  B </entry>
 B  B  B </ENDLOOP>
 B  B </LOOP>

 B  B <LOOP>
 B  B  B <STARTLOOP>
 B  B  B  B <entry>
 B  B  B  B  B <startLoop>
 B  B  B  B  B  B <loopId>2</loopId>
 B  B  B  B  B </startLoop>
 B  B  B  B </entry>
 B  B  B </STARTLOOP>
 B  B  B <ENDLOOP>
 B  B  B  B <entry>
 B  B  B  B  B <endLoop>
 B  B  B  B  B  B <loopId>2</loopId>
 B  B  B  B  B </endLoop>
 B  B  B  B </entry>
 B  B  B </ENDLOOP>
 B  B </LOOP>
 B </LOOPS>
</AAA>



XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
 B <xsl:output method="xml" omit-xml-declaration="yes"/>

 B <xsl:template match="/entries">
 B  B <AAA> B  
 B  B  B <!-- first, output sequence without loop contents -->
 B  B  B <SEQUENCE>
 B  B  B  B <xsl:for-each select="entry">
 B  B  B  B  B <xsl:choose>
 B  B  B  B  B  B <xsl:when test="not(preceding-sibling::entry[startLoop]) or preceding-sibling::entry[endLoop] and not(./endLoop)">
 B  B  B  B  B  B  B <outputEntry>
 B  B  B  B  B  B  B  B <xsl:copy-of select="."/>
 B  B  B  B  B  B  B </outputEntry>
 B  B  B  B  B  B </xsl:when>
 B  B  B  B  B </xsl:choose>
 B  B  B  B </xsl:for-each>
 B  B  B </SEQUENCE>
 B  B  B 
 B  B  B <!-- second, output each loop sequence contents -->
 B  B  B <LOOPS>
 B  B  B  B <xsl:for-each select="entry">
 B  B  B  B  B <xsl:if test="./startLoop">
 B  B  B  B  B  B <LOOP>
 B  B  B  B  B  B  B <xsl:variable name="start" select="count(preceding-sibling::*) + 1"/>
 B  B  B  B  B  B  B <xsl:variable name="end" select="$start + count(following-sibling::entry[endLoop])"/>
 B  B  B  B  B  B  B <STARTLOOP>
 B  B  B  B  B  B  B  B <xsl:copy-of select="."/>
 B  B  B  B  B  B  B </STARTLOOP>
 B  B  B  B  B  B  B <xsl:for-each select="/entries/entry[position() &gt; $start and position() &lt;= $end]">
 B  B  B  B  B  B  B  B <xsl:choose>
 B  B  B  B  B  B  B  B  B <xsl:when test="./endLoop">
 B  B  B  B  B  B  B  B  B  B <ENDLOOP>
 B  B  B  B  B  B  B  B  B  B  B <xsl:copy-of select="."/>
 B  B  B  B  B  B  B  B  B  B </ENDLOOP>
 B  B  B  B  B  B  B  B  B </xsl:when>
 B  B  B  B  B  B  B  B  B <xsl:otherwise>
 B  B  B  B  B  B  B  B  B  B <MIDDLE>
 B  B  B  B  B  B  B  B  B  B  B <xsl:copy-of select="."/>
 B  B  B  B  B  B  B  B  B  B </MIDDLE>
 B  B  B  B  B  B  B  B  B </xsl:otherwise>
 B  B  B  B  B  B  B  B </xsl:choose>
 B  B  B  B  B  B  B </xsl:for-each>
 B  B  B  B  B  B </LOOP>
 B  B  B  B  B </xsl:if>
 B  B  B  B </xsl:for-each>
 B  B  B </LOOPS>
 B  B </AAA>
 B </xsl:template>

</xsl:stylesheet>



Thanks for any advice,
Michael.

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.