XSLT obtain a value of revised element in PDF
Post here questions and problems related to editing and publishing DITA content.
-
- Posts: 21
- Joined: Wed Jun 28, 2023 11:49 pm
XSLT obtain a value of revised element in PDF
I am trying to pull a value from the critdates element, specifically <revised>.
The XML is:
When I use:
the bookpartno data is printed in the PDF.
When I run a similar code using the revised element:
nothing is returned.
I have tried various combinations of the path, such as revised/@modified, bookmap/revised/@modified, etc., and I have substituted "attribute" for "class" in the above code, but that hasn't helped.
Any ideas as to why this doesn't work for the revised element?
The XML is:
Code: Select all
<bookmeta>
<author></author>
<critdates>
<created date="2023"/>
<revised modified="2024"></revised>
</critdates>
<bookid>
<bookpartno>4598638</bookpartno>
<booknumber>6.2.0</booknumber>
</bookid>
</bookmeta>
Code: Select all
<fo:block>
<xsl:if test="//*[contains(@class, ' bookmap/bookmeta ')][1]">
<xsl:value-of select="//*[contains(@class, ' bookmap/bookpartno ')]/text()"/></xsl:if>
</fo:block>
When I run a similar code using the revised element:
Code: Select all
fo:block>
<xsl:if test="//*[contains(@class, ' bookmap/bookmeta ')][1]">
<xsl:value-of select="//*[contains(@class, ' critdates/revised/@modified ')]/text()"/></xsl:if>
</fo:block>
I have tried various combinations of the path, such as revised/@modified, bookmap/revised/@modified, etc., and I have substituted "attribute" for "class" in the above code, but that hasn't helped.
Any ideas as to why this doesn't work for the revised element?
-
- Posts: 9439
- Joined: Fri Jul 09, 2004 5:18 pm
Re: XSLT obtain a value of revised element in PDF
Hi,
I think based on your intention your XPath expression should look like this:
or this if you are not using specializations with other names for the element:
Regards,
Radu
I think based on your intention your XPath expression should look like this:
Code: Select all
<xsl:value-of select="//*[contains(@class, ' topic/critdates ')]/*[contains(@class, ' topic/revised ')]/@modified"/>
Code: Select all
<xsl:value-of select="//critdates/revised/@modified"/>
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 21
- Joined: Wed Jun 28, 2023 11:49 pm
Re: XSLT obtain a value of revised element in PDF
Thank you, Radu!
Your help is very much appreciated.
works, to a point.
However, the PDF prints 2024 2024 2024 2024 2024 2024 instead of a single instance of 2024.
I have found this happens when I use topic/ in the @class statements. I haven't found a resolution.
I also tried:
which also renders:
2024 2024 2024 2024 2024 2024
So,
works and prints only one instance of the date in the PDF.
Thanks again, Radu, for your help.
Regards
Tinmen
Your help is very much appreciated.
Code: Select all
<xsl:value-of select="//*[contains(@class, ' topic/critdates ')]/*[contains(@class, ' topic/revised ')]/@modified"/>
However, the PDF prints 2024 2024 2024 2024 2024 2024 instead of a single instance of 2024.
I have found this happens when I use topic/ in the @class statements. I haven't found a resolution.
I also tried:
Code: Select all
<xsl:value-of select="//critdates/revised/@modified"/>
2024 2024 2024 2024 2024 2024
So,
Code: Select all
<xsl:value-of select="//bookmeta/critdates/revised/@modified"/>
Thanks again, Radu, for your help.
Regards
Tinmen
Last edited by Tinmen on Thu Jul 13, 2023 8:07 pm, edited 2 times in total.
-
- Posts: 9439
- Joined: Fri Jul 09, 2004 5:18 pm
Re: XSLT obtain a value of revised element in PDF
Hi Tinmen,
Whenever you get a sequence of output values you can always do stuff like this:
to take only the first returned result.
Usually when you have problems creating XPath expressions you need to understand on what XML document they get applied. Your XSLT is applied on an XML document which is the bookmap with all topicrefs expanded in it. If you use something like:
you should get in the ANT console output the entire merged XML document printed. Then you can copy it from there, create a new XML document in Oxygen and try to run xpath expressions on it using the Oxygen XPath toolbar for example.
Regards,
Radu
Whenever you get a sequence of output values you can always do stuff like this:
Code: Select all
<xsl:value-of select="(//critdates/revised/@modified)[1]"/>
Usually when you have problems creating XPath expressions you need to understand on what XML document they get applied. Your XSLT is applied on an XML document which is the bookmap with all topicrefs expanded in it. If you use something like:
Code: Select all
<xsl:message><xsl:copy-of select="/*"/></xsl:message>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 21
- Joined: Wed Jun 28, 2023 11:49 pm
Re: XSLT obtain a value of revised element in PDF
Hi Radu:
Makes sense. I had originally tried the [1], but my syntax must have been wrong. I used your code, and it works perfectly. I did realize the multiple instances of the value matched the page count in my document. I couldn't find a way to fix it initially.
Thanks again for your tremendous support.
Regards
Tinment
Makes sense. I had originally tried the [1], but my syntax must have been wrong. I used your code, and it works perfectly. I did realize the multiple instances of the value matched the page count in my document. I couldn't find a way to fix it initially.
Thanks again for your tremendous support.
Regards
Tinment
Return to “DITA (Editing and Publishing DITA Content)”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ 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