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

Re: An XPath expression that avoids writing special ca

Subject: Re: An XPath expression that avoids writing special case code?
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 22 Jun 2021 13:59:07 -0000
Re:  An XPath expression that avoids writing special ca
Hey again,

Better:

<xsl:sequence select="$document/Row[Cell[1]/Data =
$element][not(Cell[2]/Data != $parent)]" />

Cheers, Wendell

On Tue, Jun 22, 2021 at 9:42 AM Wendell Piez <wapiez@xxxxxxxxxxxxxxx> wrote:

> Roger,
>
> Okay, so the requirement is that if Data[2] is present, it must correspond
> with the second argument. It may not be the same (if it is not there at
> all) but it must not be different.
>
> <xsl:function name="f:getRow">
>     <xsl:param name="element"/>
>     <xsl:param name="parent"/>
>     <xsl:sequence select="$document/Row[Cell[1]/Data eq
> $element][not(Cell[2]/Data ne $parent)]" />
> </xsl:function>
>
> (Untested.)
>
> Does this reflect the intent?
>
> Cheers, Wendell
>
>
> On Fri, Jun 18, 2021 at 8:58 AM Roger L Costello costello@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> Hi Wendell,
>>
>> My XML document may have an element named navaid with a parent element
>> named airport and it may have an element named navaid with a parent element
>> named enrouteAirway, like this:
>>
>> <Document>
>>     ...
>>     <Row>
>>         <Cell>
>>             <Data>navaid</Data>
>>         </Cell>
>>         <Cell>
>>             <Data>airport</Data>
>>         </Cell>
>>     </Row>
>>     ...
>>     <Row>
>>         <Cell>
>>             <Data>navaid</Data>
>>         </Cell>
>>         <Cell>
>>             <Data>enrouteAirway</Data>
>>         </Cell>
>>     </Row>
>>     ...
>> </Document>
>>
>> To identify that I want the navaid within airport (not the navaid within
>> enrouteAirway) I need to specify in the function call both element and
>> parent, e.g.,
>>
>> f:getRow('navaid', 'airport')
>>
>> Does that make sense?
>>
>> /Roger
>>
>> From: Wendell Piez wapiez@xxxxxxxxxxxxxxx <
>> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
>> Sent: Friday, June 18, 2021 8:45 AM
>> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> Subject: [EXT] Re:  An XPath expression that avoids writing special
>> casecode?
>>
>> Roger,
>>
>> I am fairly puzzled, not by the problem as posed, but whether it is
>> really the problem.
>>
>> Surely, if you had
>>
>> <xsl:function name="f:getRow">
>>     <xsl:param name="element"/>
>>     <xsl:sequence select="$document/Row[Cell[1]/Data eq $element]" />
>> </xsl:function>
>>
>> you could call
>>
>> <xsl:sequence select="f:getRow('airport')" />
>>
>> and not worry whether a parent is given or not.
>>
>> Mind you, I also agree with Mike Kay. I think this is a case where since
>> your syntax does not clearly reflect the semantics you wish to induce over
>> the data, everything becomes harder.
>>
>> So what's the real question here? My guess is it has to do with what a
>> "parent" is and why you want to look at it sometimes, but not other times.
>>
>> Cheers, Wendell
>>
>>
>> On Thu, Jun 17, 2021 at 10:06 AM Roger L Costello mailto:
>> costello@xxxxxxxxx <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
>> wrote:
>> Hi Folks,
>>
>> My XML document contains a bunch of <Row> elements, like so:
>>
>> <Document>
>>     ...
>>     <Row>
>>         <Cell>
>>             <Data>airport</Data>
>>         </Cell>
>>         <Cell>
>>             <Data>airports</Data>
>>         </Cell>
>>     </Row>
>>     ...
>> </Document>
>>
>> I want to fetch the Row whose Cell[1]/Data is 'airport' and whose
>> Cell[2]/Data is 'airports'. So I created this XPath expression:
>>
>> /Document/Row[Cell[1]/Data eq 'airport'][Cell[2]/Data eq 'airports']
>>
>> I do this kind of fetching operation often, so I created a function to
>> fetch the desired Row:
>>
>> <xsl:function name="f:getRow">
>>     <xsl:param name="element"/>
>>     <xsl:param name="parent"/>
>>     <xsl:sequence select="$document/Row[Cell[1]/Data eq
>> $element][Cell[2]/Data eq $parent]" />
>> </xsl:function>
>>
>> I call the function this way:
>>
>> <xsl:sequence select="f:getRow('airport', 'airports')" />
>>
>> Sometimes there is an element that doesn't have a parent. That is,
>> sometimes I'd like to fetch a Row in which Cell[2] is empty, like this:
>>
>>     <Row>
>>         <Cell>
>>             <Data>aviation</Data>
>>         </Cell>
>>         <Cell/>
>>     </Row>
>>
>> Then this call to f:getRow fails:
>>
>> <xsl:sequence select="f:getRow('aviation', '')" />        <!-- Those are
>> two apostrophes within the parentheses -->
>>
>> Clearly I need to modify f:getRow. I could add special case code to test
>> $parent to see if it is empty (the '' string) and do one thing, and if it's
>> not empty do another thing. But I wonder if there is a more elegant
>> solution that doesn't involve special case code? Is there a way to modify
>> the XPath expression in f:getRow such that it fetches the correct Row
>> regardless of whether $parent is empty or not?
>>
>> /Roger
>>
>>
>>
>>
>> --
>> ...Wendell Piez... ...wendell -at- nist -dot- gov...
>> ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
>> ...http://github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
>> http://www.mulberrytech.com/xsl/xsl-list
>> http://lists.mulberrytech.com/unsub/xsl-list/673357 ()
>> 
>>
>>
>
> --
> ...Wendell Piez... ...wendell -at- nist -dot- gov...
> ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
> ...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
>


-- 
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...

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.