I'm trying to construct some generic XSLT patterns for processing
typical GML documents and am struggling with a dynamic path following
issue. I've over 20 years in software development and a moderate XSLT
semantic understanding but am not yet at guru level. The num2cells
template at the end of this message is about as good as I've got :-)
I don't know if this is possible in generic XSLT. As these are
samples expected to be used by a wide community, I'm trying to avoid
extensions.
I summarise what I need as wanting to go from a string value in an
attribute to having the nodeset it refers to. So, given an href like
"../../../gml:position" I can write a generic template to invoke the
original gml:position template.
I've experimented with the document function and just had someone
else suggest it may help but I'm not sure how to use document to
refer to a different location in the current source.
Say we have some XML with a relative ref back in the file, like:
<featureMember>
<GeochemSpecimen gml:id="WA_1_139459">
<gml:name>139459</gml:name>
<gml:position
xlink:href="urn:x-seegrid:definition:gml:NilReason:unknown"/>
<material>rock</material>
<relatedObservation>
<GeochemMeasurement
gml:id="WA_1_139459_Ag">
<gml:position xlink:href="../../../gml:position"/>
I'm processing this with <xsl:apply-templates select="gml:position"/>
invoking the following
<xsl:template match="gml:position">
<xsl:choose>
<xsl:when
test="contains(@xlink:href,'gml:position')">
<!-- ref to another position, eg:
@xlink:href='../../../gml:position'-->
<!-- literal select works <xsl:apply-templates
select='../../../gml:position'/> -->
</xsl:when>
<xsl:when
test="@xlink:href='urn:x-seegrid:definition:gml:NilReason:unknown'">
<td
colspan="3">unknown</td>
</xsl:when>
<xsl:when test="gml:Point/gml:pos">
<xsl:call-template
name="num2cells">
<xsl:with-param name="numbers"
select="normalize-space(gml:Point/gml:pos)"/>
<xsl:with-param
name="colsToFill" select="3"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<td
colspan="3">unrecognised gml:position</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Recursively parse a space-delimited list into <td>
pairs, assumes single whitespace delimiters, puts colspan on blank last
entry if necessary, pass in 0 to colsToFillif don't care about padding
-->
<xsl:template name="num2cells">
<xsl:param name="numbers"/>
<xsl:param name="colsToFill"/>
<xsl:choose>
<xsl:when test="contains($numbers,'
')">
<td>
<xsl:value-of select="substring-before($numbers, ' ')"/>
</td>
<xsl:call-template
name="num2cells">
<xsl:with-param name="numbers" select="substring-after($numbers, ' ')"/>
<xsl:with-param
name="colsToFill" select="number($colsToFill)-1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$colsToFill>2">
<td><xsl:value-of
select="$numbers"/></td><td colspan="{$colsToFill-1}"> </td>
</xsl:when>
<xsl:when test="$colsToFill=2">
<td><xsl:value-of
select="$numbers"/></td><td> </td>
</xsl:when>
<xsl:otherwise> <!-- exact fit or
more cols thanexpected -->
<td><xsl:value-of
select="$numbers"/></td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Thanks for any advice
--
Andy Dent BSc MACS http://www.oofile.com.au/
OOFILE - Database, Reports, Graphs, GUI for c++ on Mac, Unix & Windows
PP2MFC - PowerPlant->MFC portability