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

Re: Best way to represent an item and its context?

Subject: Re: Best way to represent an item and its context?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Sep 2011 13:06:22 -0400
Re:  Best way to represent an item and its context?
At 2011-09-15 12:47 -0400, you wrote:
Hi Folks,

Consider this XML document:

<?xml version="1.0"?>
<Book>
      <title>GML</title>
      <author>Ron Lake</author>
      <date>2004</date>
</Book>

Suppose that while processing that XML document I get to the author element:

<author>Ron Lake</author>

Fine, so that is your current element.


I want to store this element and its context in a variable. The context of author is the entire document.

<xsl:variable name="v1" select="."/>


Now every time you access $v1 you are "dropped into" the document at the <author> element, right in its context.

You say the context is the entire document, so you could go to the top of the document in XSLT 2.0 using:

select="$v1/root()"

... or in XSLT 1.0 using:

select="$v1/ancestor::node()"

So I want a function that takes as input the author element and the Book element and returns a representation of the element and its context:

What is your purpose of using a syntactic representation? How do you plan to use that syntactic representation?


I have various functions which operate on that Item-in-Context variable. For example, one function returns the item's parent:

XPath already has all its useful axis concepts.


parent :: Item-in-Context -> Item

<xsl:function name="f:parent"> <xsl:param name="item"/> <xsl:sequence select="$item/.."/> </xsl:function>

Here I invoke the parent function and store the result into a second variable:

<xsl:template match="/">

<xsl:variable name="v1" select="f:item-in-context(Book/author, Book)" />

<xsl:variable name="v2" select="f:parent($v1)" />

</xsl:template>

What's the best way to represent an item and its context?

<xsl:variable name="v1" select="Book/author"/> <xsl:variable name="v2" select="$v1/.."/>

It looks a bit like reinventing XPath. Which you can do if you want, but what is it in XPath that prompts you to have an alternate representation?

I hope this is considered helpful and not criticizing ... I'm just curious why the existing language features are not meeting your need.

. . . . . . . . . . . Ken

--
Contact us for world-wide XML consulting and instructor-led training
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

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.