RE: [xsl] XPath to match attribute with multiple values...?

Subject: RE: [xsl] XPath to match attribute with multiple values...?
From: George James <GeorgeJ@xxxxxxxxxxxxxxx>
Date: Wed, 10 Nov 2004 22:57:00 -0000
> Michael Kay wrote:
> >With 1.0, it's much harder.

How hard is this?
	contains(concat(concat(" ",@categories)," "),concat(concat("
",$word)," "))

Or this?
	<xsl:variable name="spaceWordSpace">
	  <xsl:text> </xsl:text>
	  <xsl:value-of select="$word"/>
	  <xsl:text> </xsl:text>
	</xsl:variable>

	<xsl:variable name="spaceCategoriesSpace">
	  <xsl:text> </xsl:text>
	  <xsl:value-of select="@categories"/>
	  <xsl:text> </xsl:text>
	</xsl:variable>

and then:
	contains($spaceCategoriesSpace,$spaceWordSpace)

Regards
George

George James Software
Cachi Tools, Training, Technology
www.georgejames.com
+44-1932-252568




> -----Original Message-----
> From: Matt Dittbenner [mailto:mbditt@xxxxxxxxxxxxxxxxx]
> Sent: 10 November 2004 19:33
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] XPath to match attribute with multiple values...?
>
>
> Darn...
>
> Well, it looks like that is exactly what I want to do, but
> the engine I
> am using uses libxml which only implements XSL 1.0. Again, thanks for
> all the quick responses! Manos, thanks for checking it out
> and pointing
> me in the right direction. And Michael, you are the wisest of the
> wise...I have read many of your articles and they have been
> infinitely
> helpful to starting my journey into XSL :).
>
> Everyone else, keep helping make this one of the most active mailing
> lists I have ever seen.
>
> Matt
>
> Michael Kay wrote:
>
> >In 2.0 if you have a schema that describes the attribute as
> list-valued
> >then
> >
> >  contains(@categories, "business")
> >
> >will do the right thing.
> >
> >If you don't have a schema, then
> >
> >  contains(tokenize(@categories, '\s'), "business")
> >
> >will do the right thing.
> >
> >With 1.0, it's much harder.
> >
> >Michael Kay
> >http://www.saxonica.com/
> >
> >
> >
> >
> >>-----Original Message-----
> >>From: Emmanouil Batsis [mailto:Emmanouil.Batsis@xxxxxxxxxxx]
> >>Sent: 10 November 2004 19:03
> >>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >>Subject: Re: [xsl] XPath to match attribute with multiple values...?
> >>
> >>Matt Dittbenner wrote:
> >>
> >>
> >>
> >>>Let me show another example.....
> >>>
> >>><package name="product1" categories="personal small_business"/>
> >>><package name="product2" categories="business enterprise" />
> >>>
> >>>In this example I want to match packages that belong to the
> >>>
> >>>
> >>category
> >>
> >>
> >>>"business" exclusively (not including small business). Using the
> >>>contains function will return both product1 and product2,
> >>>
> >>>
> >>which is not
> >>
> >>
> >>>the data I am looking for.
> >>>
> >>>
> >>Ahhhh, right; sorry for the too-quick reply. I guess you need
> >>to work a
> >>little more by matching the nodes with contains, then
> >>validating them in
> >>a template with the substring functions. Check out
> >>
> >>http://www.w3.org/TR/xpath#section-String-Functions
> >>
> >>for reference. Dunno if an extention exists for what you want (ie
> >>match-word or something), but i guess it checking out EXSLT
> would not
> >>take too much time.
> >>
> >>hth,
> >>
> >>Manos
> >>
> >>
> >>
> >>>Thanks for such fast responses!
> >>>
> >>>Emmanouil Batsis wrote:
> >>>
> >>>
> >>>
> >>>>An attribute value is atomic. You can look whether it contains a
> >>>>substring using the contains(a, b) function. It will
> >>>>
> >>>>
> >>return true if a
> >>
> >>
> >>>>contains b.
> >>>>
> >>>>hth,
> >>>>
> >>>>MAnos
> >>>>
> >>>>Matt Dittbenner wrote:
> >>>>
> >>>>
> >>>>
> >>>>>Hey there,
> >>>>>
> >>>>>I am having trouble finding any information on this. I
> >>>>>
> >>>>>
> >>have some XML
> >>
> >>
> >>>>>data with an attribute that has a space-delimited list
> >>>>>
> >>>>>
> >>inside of it
> >>
> >>
> >>>>>(kind of like putting multiple classes on an element in
> >>>>>
> >>>>>
> >>html for use
> >>
> >>
> >>>>>by CSS). How can I use XPath to match the nodes with
> >>>>>
> >>>>>
> >>attributes that
> >>
> >>
> >>>>>contain a specific value. I think the best way to describe this
> >>>>>would be with an example:
> >>>>>
> >>>>><data>
> >>>>>   <item name="a" attribute="value value1"/>
> >>>>>   <item name="b" attribute="value2 value1"/>
> >>>>>   <item name="c" attribute="value1 value3"/>
> >>>>>   <item name="d" attribute="value"/>
> >>>>></data>
> >>>>>
> >>>>>If I want to match the elements where "attribute" has one of its
> >>>>>values "value1", I want item "a", item "b" and item "c".
> But if I
> >>>>>want the elements where "attribute" has one of its values
> >>>>>
> >>>>>
> >>"value", I
> >>
> >>
> >>>>>should get item "a" and item "d". If you use the
> >>>>>
> >>>>>
> >>contains() string
> >>
> >>
> >>>>>function, you would obviously match all items, which is
> >>>>>
> >>>>>
> >>not what I
> >>
> >>
> >>>>>want.
> >>>>>
> >>>>>As I said before CSS allows you to create styles that apply to a
> >>>>>class, and on your html, you can just set class="class1 class2
> >>>>>class3". That way ".class1", ".class2", ".class3", and
> >>>>>".class1.class2" are all separate styles! I don't need
> >>>>>
> >>>>>
> >>this extent
> >>
> >>
> >>>>>of functionality, but it leads me to believe something like this
> >>>>>just might exist in XPath.
> >>>>>
> >>>>>Any ideas?
> >>>>>
> >>>>>Thanks in advance,
> >>>>>   Matt

Current Thread