xsl-list
[Top] [All Lists]

Re: [xsl] Finding Any Occurrance

2006-09-01 12:16:05
Hi, Bob,

A trick that you'll quickly master is creating what I call an "anchor
variable" whenever you need to hang on to the current context. Consider the
following block of XSLT:

<xsl:template match="widget">
  <xsl:variable name="this-context" select="."
  <xsl:for-each select="/doc/some-other-widget">
    <!-- Get the value of the current context -->
    <xsl:value-of select="."/>
    <!-- Get the value of the saved context -->
    <xsl:value-of select="$this-context"/>
  </xsl:for-each>
</xsl:template>

HTH

Jay Bryant
Bryant Communication Services

----- Original Message ----- 
From: "Bob Portnell" <simply(_dot_)bobp(_at_)gmail(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Friday, September 01, 2006 1:35 PM
Subject: Re: [xsl] Finding Any Occurrance


It does indeed help! Sorry I was unclear, where I was. $matcher is not
containing a result tree fragment, near as my result document tells me
... value-of $matcher gives me the nice string I want to search
against. (I'm in XSLT 2.0, as I ought to have said and didn't.)

It turns out my problem is actually about context. I'm inside a
for-each loop at that point, with that loop's context pointing out
into the outside document. I need to get myself back into the source
document somehow. Ew. Am I going to have to explicitly call the
document every time I want something from it?

Happy to take more advice,

Bob P
simply(_dot_)bobp(_at_)gmail(_dot_)com

On 9/1/06, Abel Online <abel(_dot_)online(_at_)xs4all(_dot_)nl> wrote:
Hi Bob,

It'd be informative to know what you mean with "doesn't work". Do you
mean that there's no match? Or do you mean that the result is different
than from what you expected?

The expression //title will retrieve all the title nodes. Unless all
these titles together match your $matcher, you will have a true match
(and I think this depends on the XSLT version you use, because in XSLT
1, I think $matcher contains a result tree fragment, which will not
match). If what you are after is that the text of the titles should be
matched against $matcher, you may try the following:.

<xsl:if test="//title[. = $matcher]"> ... </xsl:if>

In which case the test will be true if at least one of the title tags
contains the text in $matcher. Perhaps this is even better

<xsl:if test="//title[normalize-space(.) = normalize-space($matcher)]">
... </xsl:if>

Hope this helps,

Cheers,

Abel Braaksma
http://abelleba.metacarpus.com


Bob Portnell wrote:
(Another baby question, but at least it's on-topic)

I have (successfully!) pulled some content from an outside file (and
hidden it in the variable $matcher). I now want to look through my
input file to see if that content is in any <title> child, anywhere,
so I know if it's worth carrying on processing for this content. But

<xsl:if test="//title = $matcher">

doesn't work. What have I overlooked?

(US correspondents, have a great holiday weekend!)

Bob P
simply(_dot_)bobp(_at_)gmail(_dot_)com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>