[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: match multiple values for an attribute
Subject: Re: match multiple values for an attribute
From: Jeff Sese <jsese@xxxxxxxxxxxx>
Date: Wed, 30 Aug 2006 16:52:11 +0800
|
Thanks Florent for your suggestion.
I did solve the problem, however, using a different approach. I'm using
XSLT 2.0 so I just used the matches function using a regular expression:
matches(@style, 'font-family: (font1|font2)')
I converted the $fonts into a string separated by the '|' operator.
--
Jeff Sese**
Florent Georges wrote:
Jeff Sese wrote:
Hi
have an xml with elements like these:
<par @style="font-family: some.font.name; some.more.string">some
text</par>
and i have an variable in my xsl file like this:
<xsl:variable name="fonts" as="xs:string+"
select="('font1','font2')"/>
i want to match the text nodes that are child of an
element with a style attribute that matches any of the
fonts in $fonts. What is the xpath expression that can do
that?
It depends. The most simple way is to use contains(). It
is not the a perfect way, but it can be acceptable if the
font names are complex enough and you know you'll never have
them as substring of @style but for font names.
It depends also if you use XSLT 1.0 or 2.0, and if you
have EXSLT support for regexp.
In the worst case (plain XSLT 1.0 and you must to match
exactly the format of @style), you'll have to parse the
string. For example:
named template STYLE-MATCH-FONT-P:
input: string
return: boolean
if not(string)
return FALSE
else
property <- substring-before($string, ';')
name <- normalize-space(substring-before($property, ':'))
if $name = 'font-familiy'
value <- normalize-space(substring-after($property, ':'))
if $value = $fonts
return TRUE
else
return FALSE
else
STYLE-MATCH-FONT-P(substring-after($string, ';'))
You'll have to adapt it to your precise problem: can
'font-family' appear several times in the string?, can its
value contain several font names?, etc.
Reagrds,
--drkm
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|