Awkward XPath reference

Here should go questions about transforming XML with XSLT and FOP.
david_himself
Posts: 43
Joined: Mon Oct 01, 2018 7:29 pm

Awkward XPath reference

Post by david_himself »

We have started marking precision on some XML date elements. An invented maximal example is as follows:

<date when="1815-01-06" notBefore="1814-10" notAfter="1815">6 January c1815
<precision match="@when" precision="medium"/>
<precision match="@notBefore" precision="high"/>
<precision match="@notAfter" precision="medium"/>
</date>

My XSLT 1.0 script (XML to HTML) displays the content of the date element, here "6 January c1815". I added a small template to be called after the date display and having no effect unless there are one or more <precision> children:

<xsl:template name="datePrecision">
<xsl:for-each select="TEI/teiHeader/profileDesc/correspDesc/correspAction[@type='sent']/date/precision">
<br/><xsl:value-of select="substring-after(./@match,'@')" /><xsl:text> </xsl:text><xsl:value-of select="???" /> <xsl:text> (precision: </xsl:text><xsl:value-of select="./@precision" />)
</xsl:for-each>
</xsl:template>

The problem is the emboldened, red element, which is meant to be the value of the attribute in <date> whose name (plus @ sign) is given in @match in the relevant <precision> child. What is the XPath formula which will identify this value?

Thanks for any help [or suggestions for a simpler way of achieving the same end].
Radu
Posts: 9473
Joined: Fri Jul 09, 2004 5:18 pm

Re: Awkward XPath reference

Post by Radu »

Hi,

Probably you can replace that xsl:value-of with:

Code: Select all

<xsl:variable name="matchAttrName" select="substring-after(@match, '@')"/>
<xsl:value-of select="parent::date/@*[local-name()= $matchAttrName]" />
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
david_himself
Posts: 43
Joined: Mon Oct 01, 2018 7:29 pm

Re: Awkward XPath reference

Post by david_himself »

Works a treat. Thank you.

D
Post Reply