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(_at_)CraneSoftwrights(_dot_)com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
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>
--~--