This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

M.Kay XSLT book, p. 120 Curly braces question


On page 120 of his XSLT book, Michael Kay describes where the curly
braces construct can and cannot be used. In the example at the top of
the page he describes a situation where it cannot be used, but fails to
give an alternative solution. 
I am at the moment facing a similar problem, where I would like to use a
variable or parameter as part of an XPath expression. However, whereas I
can use variables in constructions such as
$doc/FeatureSet[$i]/Feature[$j], where $doc is a nodeset generated by 

<xsl:variable name="doc" select="document(@FeatureFile)"/>

I cannot use a construction like $doc//$mypointer, where $mypointer has
the value 'FeatureSet[2]/Feature[4]'. (saxon & xt both balk at the
second $ sign in the expression)

To illustrate my point I'll include my xml and xsl fragments:

XML:

In my xml file which describes my data, I want to include a reference to
the original data that was used in the calculation. Since that data,
too, is stored in an XML file, I would ideally store an xpointer in one
of the attributes, and use that directly in my XSL stylesheet. 
Failing to do so, I then started using an additional attribute for
storing the counters. These I can use easily in my stylesheet, as the
example shows. 

<EventNode Id='1' FeatureFile='f1.xml' Fid="1.2"
FeatureId='FeatureSet[1]/Feature[2]' EventIn='CONT' EventOut='CONT'/>
<EventNode Id='2' FeatureFile='f1.xml' Fid="1.1"
FeatureId='FeatureSet[1]/Feature[1]' EventIn='CONT' EventOut='CONT'/>

XSL:

I use the document functiont to retrieve the external document (f1.xml)
as a nodeset, and I can then use constructions such as: 

<xsl:template match="EventNode">
<li>
Hello World : <xsl:value-of select="@Id"/>
<xsl:value-of select="@EventIn"/>
<xsl:value-of select="@EventOut"/>
<xsl:variable name="doc" select="document(@FeatureFile)"/>
<xsl:apply-templates select="$doc//FeatureSet[1]/Feature[1]"/>
</li>
</xsl:template>

(the rest of the stylesheet of course has appropriate templates for the
FeatureSet & Feature tags)
or even: 

<xsl:apply-templates
select="$doc/FeatureSet[substring-before($Fid,'.')]/Feature[substring-after($Fid,'.')]"/>


However, I would like to be able to use @FeatureId directly: 

<xsl:apply-templates select="document(@FeatureFile)//{@FeatureId}"/>

Or even by catching the xpointer in a variable first and then using a
concat: 

<xsl:variable name="doc" select="document(@FeatureFile)"/>
<xsl:variable name="pointer" select="@FeatureId"/>

<xsl:variable name="pointertwo"
select="concat('$doc','//',@FeatureId)"/>
or 
<xsl:variable name="pointertwo" select="concat('$doc','//',$pointer)"/>

<xsl:apply-templates select="$pointertwo"/>

=====
Any and all help will be greatly appreciated,
Gert Bultman
Delft Technical University
Computer Graphics Dept.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]