Re: Help getting the difference of two attribute lists
Martin Honnen <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.layout.xslt |
|---|---|
| Organization | Liberty Development |
| Message-ID | <[email protected]> |
[email protected] wrote: > I have two lists of attributes ($attr1, $attr2). I want to make a list > ($attr3) that will be everything found in $attr1 and NOT in $attr2. > example: > > doc1.xml: > > <attr1 a=5 b=6 c=7/> > <attr2 c=7 b=6/> Where are the quotes around the attribute values? > Running this code: > > <xsl:variable name="attr1" select="attr1\@*"/> att1/@* > <xsl:variable name="attr2" select="attr2\@*"/> att1/@* > Returns this: > > $attr1[0] = 'a' 5 No, the index in XPath node sets starts with 1 not with 0. > $attr1[1] = 'b' 6 > $attr1[2] = 'c' 7 > > $attr2[0] = 'c' 7 // Notice that its not ordered > $attr2[1] = 'b' 6 > > What I would like to get in attr3 is this: > > $attr3[0] = 'a' 5 <- in attr1 and NOT in attr2 If you only want to compare by attribute values then e.g. <xsl:variable name="attr1" select="attr1/@*"/> <xsl:variable name="attr2" select="attr2/@*"/> <xsl:variable name="attr3" select="$attr1[not(. = $attr2)]"/> suffices. If you want to compare attribute names and values then I don't think that a single expression suffices with XPath 1.0, you will need to write a template in XSLT. -- Martin Honnen http://JavaScript.FAQTs.com/