Subject: RE: [xsl] Optimization issue with includes and attribute-sets From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Mon, 29 Jan 2007 20:22:40 -0000 |
Saxon is doing pretty well exactly what the spec says it should do: you've included the module containing the attribute set twice, so you have two different attribute sets with the same name, and when you do use-attribute-sets, all attribute sets with the given name are processed and hte results are merged. Saxon could optimize this, but attribute sets are used so rarely that they don't get much attention as far as performance is concerned. (At one time I was planning to do all the merging of attribute sets at compile time, but I decided to wait until I saw a real user need: it didn't seem worth the risk of introducing bugs.) The simplest solution is to only include attributes.xsl once. You can include it from anywhere, and the named attribute sets will be available everywhere, not only in the including module. For a more sophisticated solution see the Note in section 3.10.2 of the spec: Note: It is not intrinsically an error for a stylesheet to include the same module more than once. However, doing so can cause errors because of duplicate definitions. Such multiple inclusions are less obvious when they are indirect. For example, if stylesheet B includes stylesheet A, stylesheet C includes stylesheet A, and stylesheet D includes both stylesheet B and stylesheet C, then A will be included indirectly by D twice. If all of B, C and D are used as independent stylesheets, then the error can be avoided by separating everything in B other than the inclusion of A into a separate stylesheet B' and changing B to contain just inclusions of B' and A, similarly for C, and then changing D to include A, B', C'. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Angela Williams [mailto:Angela.Williams@xxxxxxxxxxxxxxxxxx] > Sent: 29 January 2007 19:56 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Optimization issue with includes and attribute-sets > > Greetings! > > Using xslt 2.0, xpath 2.0, xsl-fo, saxon8b: > > I have a stylesheet that contains all of my attribute sets > for a complex transformation. The templates are modularized > in separate files that may include the attributes.xsl and one > or more of the other templates. > This is causing the attribute set to be applied once for > every file that directly or indirectly references it - > sometimes 20 times for a single block. While this doesn't > cause a problem in the output, it sure is not optimized. For > example, the code below applies each attribute set twice. > > I had a similar problem when one of the files contained a > named template. I had to change the include to import to > avoid the duplicate template error, but that doesn't fix this > issue. What do I need to do to resolve this, seemingly > bizarre, behavior? > > Thanks in advance! > Angela Williams, Developer > The 401(k) Company > > <!-- main-junk.xsl --> > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0"> > > <xsl:include href="junk2.xsl" /> > <xsl:include href="junk3.xsl" /> > > <xsl:template match="/"> > <xsl:apply-templates select="*" /> > </xsl:template> > </xsl:stylesheet> > > > <!-- junk2.xsl --> > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0"> > > <xsl:include href="attributes.xsl" /> > > <xsl:template match="test"> > <fo:block xsl:use-attribute-sets="test"> > Test: <xsl:value-of select="." /> > </fo:block> > </xsl:template> > </xsl:stylesheet> > > > <!-- junk3.xsl --> > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0"> > > <xsl:include href="attributes.xsl" /> > > <xsl:template match="text"> > <fo:block xsl:use-attribute-sets="text"> > Text:<xsl:value-of select="." /> > </fo:block> > </xsl:template> > </xsl:stylesheet> > > > <!-- attributes.xsl --> > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0"> > > <xsl:attribute-set name="text"> > <xsl:attribute name="font-weight">bold</xsl:attribute> > <xsl:attribute name="font-size">16pt</xsl:attribute> > <xsl:attribute name="font-color">red</xsl:attribute> > </xsl:attribute-set> > > <xsl:attribute-set name="test"> > <xsl:attribute name="font-weight">normal</xsl:attribute> > <xsl:attribute name="font-size">24pt</xsl:attribute> > <xsl:attribute name="font-color">blue</xsl:attribute> > <xsl:attribute name="font-style">italic</xsl:attribute> > </xsl:attribute-set> > </xsl:stylesheet> > > > <!-- junk.xml --> > <?xml version="1.0" encoding="UTF-8"?> > > <junk> > <test>Testing it</test> > <text> This is the text.</text> > </junk>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Optimization issue with inclu, Angela Williams | Thread | Re: [xsl] Optimization issue with i, David Carlisle |
[xsl] Optimization issue with inclu, Angela Williams | Date | Re: [xsl] Optimization issue with i, David Carlisle |
Month |