Subject: RE: Re: [xsl] XSLT Subtract function? From: cknell@xxxxxxxxxx Date: Fri, 13 Apr 2007 11:46:58 -0400 |
Thanks. There was a tickle somewhere in the back of my brain about not being able to evaluate a variable as XPath, but I couldn't put my hands on it. Now that you have spelled it out, I know what that tickle was. I'll examine your key suggestion closely. I was able to do Meunchian grouping from time to time in XSLT 1.0 days, but I can't say I spent much time trying to understand exactly what was going on. (No, I take that back, I do remember spending some time on it one afternoon and grasping the idea, but it has since slipped back into mental oblivion.) I take it the reason for using a key is performance? (It certainly isn't because it's easier to read and interpret.) On my data set the performance was under 10 seconds, good enough for my needs. -- Charles Knell cknell@xxxxxxxxxx - email -----Original Message----- From: David Carlisle <davidc@xxxxxxxxx> Sent: Fri, 13 Apr 2007 16:28:57 +0100 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] XSLT Subtract function? > > What I had in mind is a function that would take four arguments: > > 1) A base document (base document) [$base] > 2) A document containing the values to subtract from the base document (exemplar document) [$exemplar] > 3) The XPath to the elment in the base document holding the values of interest. [$base-element] > 4) The XPath to the element in the exemplar document holding the values of interest. [$list-element] > I'm not sure quite what you want as there can't be a _function_ like this as you can't pass an unevaluated XPath to a function (without using extensions like saxon:evaluate) so any pure xslt solution will have to have (3) and (4) appearing directly in some XSLT or Xpath expression, in which case the resulting construct is going to look rather like what you say you did already, although (especially in xslt 2) I'd use a key rather than CODE = $active-codes/ROWSET/ROW/CODE something like <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="e" select="doc('exemplar.xml')"/> <xsl:key name="x" match="sku" use="."/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="@*[key('x',.,$e)]"/> <xsl:template match="node()[key('x',.,$e)]"/> </xsl:stylesheet> $ saxon8 -sall base.xml subtract.xsl \!indent=yes <?xml version="1.0" encoding="UTF-8"?> <grocery-list> <item>milk</item> <item>cheese</item> <item>coffee</item> <item>asparagus</item> </grocery-list>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSLT Subtract function?, Dimitre Novatchev | Thread | Re: [xsl] XSLT Subtract function?, David Carlisle |
Re: [xsl] XSLT Subtract function?, Dimitre Novatchev | Date | RE: Re: [xsl] XSLT Subtract functio, cknell |
Month |