Page 1 of 1

Awkward XPath reference

Posted: Mon Oct 01, 2018 7:53 pm
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"/>

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" />)

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].

Re: Awkward XPath reference

Posted: Tue Oct 02, 2018 10:38 am
by Radu

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]" />

Re: Awkward XPath reference

Posted: Tue Oct 02, 2018 10:54 am
by david_himself
Works a treat. Thank you.