Subject: Re: [xsl] linkdiff template From: Guy McArthur <guym@xxxxxxxxxxxxxxx> Date: Mon, 17 Jun 2002 22:09:29 -0700 (MST) |
On Thu, 13 Jun 2002, Joerg Heinicke wrote: > Sorry, a litle mistake. It has to be > > <xsl:for-each select="document($previous)"> > > of course. > I thought I understood, but I get an "unknown error in XPath" on line 12. Here is the xsl I'm using: (also tried putting wrapping the key() method with a boolean() method. -- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="previous"/> <xsl:key name="links" match="a" use="@href"/> <xsl:output method="text"/> <xsl:template match="a"> <xsl:variable name="href" select="@href"/> <xsl:for-each select="document($previous)"> <xsl:if test="not(key('links', $href))"> <xsl:value-of select="$href"/> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> -- Also, it would seem by looking at it, that it would walk through all the elements of document($previous) for every matching "a" element. Shouldn't building a key eleminate the need to walk through the tree each time? Guy > > Joerg Heinicke wrote: > > A key in XSLT is always created for every XML-tree. So you don't need a > > document() in the key's use-attribute. With your declaration the key of > > the indexed links is always the value of the first a/@href in $previous. > > > > <xsl:key name="links" match="a" use="@href"/> > > > > <xsl:param name="previous"/> > > > > <xsl:template match="a"> > > <xsl:variable name="href" select="@href"/> > > <xsl:for-each select="$previous"> > > <xsl:if test="not(key('links', $href))"> > > <xsl:value-of select="$href"/> > > </xsl:if> > > </xsl:for-each> > > </xsl:template> > > > > Regards, > > > > Joerg > > > > Guy McArthur wrote: > > > >> Hi, I'm looking to write a template to output the a/@href's from one > >> (newer) file that are *not* present in another (older) file. > >> > >> I.e. given the following two files > >> -old.xml- > >> <html> > >> <a href="http://www.google.com/>Google!</a> > >> <a href="http://w3.org/">W3C</a> > >> </html> > >> -new.xml- > >> <html> > >> <a href="http://w3.org/">W3C</a> > >> <a href="http://guymcarthur.com">My HomePage</a> > >> <a href="http://xml.apache.org/xalan/">Xalan</a> > >> </html> > >> -- > >> The output would be: > >> http://guymcarthur.com > >> http://xml.apache.org/xalan/ > >> > >> Here's my first stab at the stylesheet: > >> -linkdiff.xsl- > >> <xsl:stylesheet version="1.0" > >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > >> > >> <xsl:param name="previous"/> > >> > >> <xsl:key name="links" match="a" use="document($previous)///a/@href"/> > >> > >> <xsl:output method="text"/> > >> > >> <xsl:template match="a"> > >> <xsl:if test="not(boolean(key('links', @href)))"> > >> <xsl:value-of select="@href"/> > >> </xsl:if> > >> </xsl:template> > >> > >> </xsl:stylesheet> -- > >> > >> However, it is just outputting all the href's (test is always true). > >> Please enlighten me! > >> > >> I'm using 'java org.apache.xalan.xslt.Process -IN new.xml -XSL \ > >> linkdiff.xsl -PARAM previous old.xml'. > >> > >> GKM > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > -- -- Guy McArthur * email{guym@xxxxxxxxxxx} http{guymcarthur.com} LPL Rm. #538 * w{520-621-6373} h{520-326-4555} icq{17470307} XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] linkdiff template, Joerg Heinicke | Thread | Re: [xsl] linkdiff template, Joerg Heinicke |
Re: [xsl] selecting an element in a, Jarkko . Moilanen | Date | Re: [xsl] Template priority, Peter Davis |
Month |