Awkward XPath reference

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

Awkward XPath reference

Post by david_himself » Mon Oct 01, 2018 7:53 pm

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: 6335
Joined: Fri Jul 09, 2004 5:18 pm

Re: Awkward XPath reference

Post by Radu » Tue Oct 02, 2018 10:38 am

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: 10
Joined: Mon Oct 01, 2018 7:29 pm

Re: Awkward XPath reference

Post by david_himself » Tue Oct 02, 2018 10:54 am

Works a treat. Thank you.

D

Post Reply