Subject: [xsl] build a select clause or dynamic URI's From: Andy Dent <dent@xxxxxxxxxxxxx> Date: Wed, 10 Nov 2004 07:52:24 +0800 |
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 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.
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">
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="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>
Andy Dent BSc MACS http://www.oofile.com.au/ OOFILE - Database, Reports, Graphs, GUI for c++ on Mac, Unix & Windows PP2MFC - PowerPlant->MFC portability
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Create a bit mask ?, Saba | Thread | Re: [xsl] build a select clause or , M. David Peterson |
Re: [xsl] Re: Move (ascend) an elem, Wendell Piez | Date | Re: [xsl] build a select clause or , M. David Peterson |
Month |