cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

XPath in Stylesheet

GarethOakes
16-Pearl

XPath in Stylesheet

Hey gurus,

Today's question relates to the use of XPath in the stylesheet. If you
wanted to display some text via XPath, that all works no worries, eg.
/book/metadata/author[@id="bob"]/surname

However, if you wanted to lookup the author dependant upon the current
node, it is not obvious how to resolve that. In other words, the text
"bob" should not be hardcoded in my stylesheet, as the name appears in
an attribute on the current element I'm formatting.

For example, I want to grab the author surname, as above, but now I need
the author to be "chris". Each XML element I'm formatting carries the
author ID as an attribute.

What I'm trying to achieve is analagous to a cross-reference, but rather
than resolving the generated numbering or page number for a
chapter/section/figure I'm looking up an author element by ID and
getting the surname.

I'm working in a Styler environment on 5.3.

Any ideas? I don't want to do any preprocessing on this content.

(I assume with FOSI you could use something like time-independent
variables to store the text and resolve it later?)

Cheers,
Gareth
3 REPLIES 3

Speaking strictly to the XPath part of the question, your example would become
/book/metadata/author[@id=current()/@id]/surname

That's purely XPath syntax. So long as the Styler interface fully understands XPath, that should get you what you want when used in the same location as your version. If it does not fully understand, then someone who knows its full limitations (we don't use Styler) will have to help here.

HTH,
Steve Thompson
+1(316)977-0515

Actually, the current() function is not XPath, it's XSLT.

So you could use it in XSLT edited source in Styler, but
not in places where Styler expects an XPath expression.

I'm not sure I'm understanding the exact request, but I'll
try to say some hopefully useful things.

If the current element has an idref attribute whose value
is the id of an author element whose surname child you want,
you can use the XPath id() function: id(@idref)/surname.

In 5.3, there are some restrictions on the use of the id()
function in Styler XSLT outputs, so the above XPath may not
work as desired. In 5.4 M010, this has been fixed. If
you need this to work for XSLT outputs in 5.3, I might be
able to suggest some workaround, but I'll wait to hear if
that is the case before getting more complicated.

paul

Thanks Paul, I had totally forgotten about the id() function. That
solves my particular problem perfectly 🙂

I'll bear in mind your statement about the XSLT problems in 5.3, but I
think we are only going out to PDF via FOSI at this stage.

Cheers,
Gareth

PS. Thanks also Steve for your input, but as Paul correctly pointed out
we are not in an XSLT environment 😞

Grosso, Paul wrote:
> Actually, the current() function is not XPath, it's XSLT.
>
> So you could use it in XSLT edited source in Styler, but
> not in places where Styler expects an XPath expression.
>
> I'm not sure I'm understanding the exact request, but I'll
> try to say some hopefully useful things.
>
> If the current element has an idref attribute whose value
> is the id of an author element whose surname child you want,
> you can use the XPath id() function: id(@idref)/surname.
>
> In 5.3, there are some restrictions on the use of the id()
> function in Styler XSLT outputs, so the above XPath may not
> work as desired. In 5.4 M010, this has been fixed. If
> you need this to work for XSLT outputs in 5.3, I might be
> able to suggest some workaround, but I'll wait to hear if
> that is the case before getting more complicated.
>
> paul
>
>
Announcements

Top Tags