[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to do macro substitution in XPath?

Subject: Re: How to do macro substitution in XPath?
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 2 Dec 2023 17:57:07 -0000
Re:  How to do macro substitution in XPath?
Here is the wanted "pure XPath" that preserves the "readability":

      let $LBJ := /Book/Title eq 'Path to Power' and /Book/Author eq
'Robert A. Caro',
          $RM  := /Book/Title eq 'Power Broker' and /Book/Author eq 'Robert
A. Caro'
        return
          if($LBJ) then 'action 1'
          else if($RM) then 'action 2'
          else 'Error'

On Sat, Dec 2, 2023 at 7:36b/AM Roger L Costello costello@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi Folks,
>
> I am converting prose like this:
>
> If the title = "Path to Power" and the author = "Robert A. Caro" (Lyndon
> Baines Johnson (LBJ)), then
> process LBJ as follows
>     action 1
> If the title = "Power Broker" and the author = "Robert A. Caro" (Robert
> Moses (RM)), then
> process RM as follows
>     action 2
> Neither LBJ nor RM
>     action 3
>
> I need the XPath to be as like the prose as possible.
>
> Suppose the XPath will operate on XML documents like this:
>
> <Book>
>   <Title>Path to Power</Title>
>   <Author>Robert A. Caro</Author>
> </Book>
>
> Below is one approach to writing the XPath. See the XPath in the
> xsl:value-of element. Notice the use of XML ENTITIES.
>
> The advantage of that approach is the XPath looks like the prose.
>
> The disadvantage with that approach is that ENTITIES are not XPath. I need
> to stick with pure XPath. What XPath do you recommend?
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE xsl:stylesheet[
>     <!ENTITY LBJ "((/Book/Title eq 'Path to Power') and (/Book/Author eq
> 'Robert A. Caro'))">
>     <!ENTITY RM "((/Book/Title eq 'Power Broker') and (/Book/Author eq
> 'Robert A. Caro'))">
> ]>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="3.0">
>     <xsl:template match="/">
>         <xsl:value-of select="
>             if &LBJ; then
>                 'action 1'
>             else if &RM; then
>                 'action 2'
>             else if (not((&LBJ;) or (&RM;))) then
>                 'action 3'
>             else
>                 'Error'
>             "/>
>     </xsl:template>
> </xsl:stylesheet>
>
>
>

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.