Awkward XPath reference
Here should go questions about transforming XML with XSLT and FOP.
-
- 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].
<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].
-
- Posts: 9473
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Awkward XPath reference
Hi,
Probably you can replace that xsl:value-of with:
Regards,
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]" />
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 43
- Joined: Mon Oct 01, 2018 7:29 pm
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service