Dynamic xi:include/xpointer resolution
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 7
- Joined: Thu Dec 11, 2008 6:14 am
Dynamic xi:include/xpointer resolution
Hey everybody,
if this is not an XSLT but an XInclude question, I apologize in advance.
I'm working on book-type documents and I'm trying to pull in bibliographic information/document fragments of works mentioned/cited in ptr elements' @target attributes in a text document (1. content.xml) from a bibliography master file (2. master-biblio.xml) with an XSL transform (3. transform.xsl) in order to achieve something like 4. desired-output.xml. (N.B.: I am aware that I should use a unique list based on keys for that purpose; the following code samples are simplified.)
Specifically, I seem to have problems (Saxon 6.5.5: "InvalidShortHandPointer: The NCName of the ShortHand Pointer '{$currentID}' is invalid.") with evaluating what I want to pass to the xpointer attribute as a value.
Please ignore tei:teiHeader elements below. My problem seems to occur at the line in "3. XSL transform" below.
Any comments are highly appreciated!
1. Source document (content.xml):
2. Master bibliography file to be referenced/processed for fragment inclusion (master-biblio.xml):
3. XSL transform (transform.xsl):
4. Desired output (desired-output.xml):
Markus Flatscher
Editor
The Collected Works of Ferdinand Ebner (Austrian Science Fund Project #P18428)
markus.flatscher@gmail.com
http://www.ebner-gesellschaft.org
if this is not an XSLT but an XInclude question, I apologize in advance.
I'm working on book-type documents and I'm trying to pull in bibliographic information/document fragments of works mentioned/cited in ptr elements' @target attributes in a text document (1. content.xml) from a bibliography master file (2. master-biblio.xml) with an XSL transform (3. transform.xsl) in order to achieve something like 4. desired-output.xml. (N.B.: I am aware that I should use a unique list based on keys for that purpose; the following code samples are simplified.)
Specifically, I seem to have problems (Saxon 6.5.5: "InvalidShortHandPointer: The NCName of the ShortHand Pointer '{$currentID}' is invalid.") with evaluating what I want to pass to the xpointer attribute as a value.
Please ignore tei:teiHeader elements below. My problem seems to occur at the line
Code: Select all
<xi:include href="master-biblio.xml" xpointer="{$currentID}"/>
Any comments are highly appreciated!
1. Source document (content.xml):
Code: Select all
<?oxygen RNGSchema="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/teilite.rng" type="xml"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Title</title>
</titleStmt>
<publicationStmt>
<p>Publication information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<p>We cite this (<ptr target="#this"/>) and that (<ptr target="#that"/>).</p>
</body>
</text>
</TEI>
Code: Select all
<?oxygen RNGSchema="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/teilite.rng" type="xml"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Title</title>
</titleStmt>
<publicationStmt>
<p>Publication information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<listBibl>
<bibl xml:id="this">This name: this title, blah</bibl>
<bibl xml:id="that">That name: that title, bleh</bibl>
</listBibl>
</body>
</text>
</TEI>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xi="http://www.w3.org/2001/XInclude">
<xsl:template match="/">
<xsl:element name="list">
<xsl:for-each select="//tei:ptr">
<xsl:sort select="@target"/>
<xsl:element name="item">
<xsl:variable name="currentID" select="substring-after('@target','#')"/>
<xi:include href="master-biblio.xml" xpointer="{$currentID}"/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<list>
<item>
<bibl xmlns="http://www.tei-c.org/ns/1.0" xmlns:xi="http://www.w3.org/2001/XInclude"
xml:id="that" xml:base="master-biblio.xml">That name: that title, bleh</bibl>
</item>
<item>
<bibl xmlns="http://www.tei-c.org/ns/1.0" xmlns:xi="http://www.w3.org/2001/XInclude"
xml:id="this" xml:base="master-biblio.xml">This name: this title, bleh</bibl>
</item>
</list>
Markus Flatscher
Editor
The Collected Works of Ferdinand Ebner (Austrian Science Fund Project #P18428)
markus.flatscher@gmail.com
http://www.ebner-gesellschaft.org
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Dynamic xi:include/xpointer resolution
Post by sorin_ristache »
Hello,
Regards,
Sorin
The xi:include element is resolved before the XSLT is applied by the XSLT processor and at that moment the parser does not know about the XST variable currentID. You have to replace the xi:include element with:mflat wrote:My problem seems to occur at the lineCode: Select all
<xi:include href="master-biblio.xml" xpointer="{$currentID}"/>
Code: Select all
<xsl:copy-of select="doc('master-biblio.xml')//*[@xml:id=$currentID]"/>
Regards,
Sorin
-
- Posts: 7
- Joined: Thu Dec 11, 2008 6:14 am
Re: Dynamic xi:include/xpointer resolution
Sorin,
thank you very much for your response -- that makes sense.
However, now I have a different question that seems to have to do with the evaluation of the variable. Substituting the original xinclude line with your suggestion,
doesn't seem to work. (N.B.: changed "doc()" to "document()")
But if I substitute a literal value, e.g.
I get the desired result.
What am I missing?
Thank you very much!
Markus
thank you very much for your response -- that makes sense.
However, now I have a different question that seems to have to do with the evaluation of the variable. Substituting the original xinclude line with your suggestion,
Code: Select all
<xsl:copy-of select="document('master-biblio.xml')//*[@xml:id=$currentID]"/>
But if I substitute a literal value, e.g.
Code: Select all
<xsl:copy-of select="document('master-biblio.xml')//*[@xml:id='this']"/>
What am I missing?
Thank you very much!
Markus
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Dynamic xi:include/xpointer resolution
Hi Markus,
The problem is here:
You quoted the first argument of substring-after and that gives you the "@target" string instead of evaluating to the target attribute. You need to change that to
Best Regards,
George
The problem is here:
Code: Select all
<xsl:variable name="currentID" select="substring-after('@target','#')"/>
Code: Select all
<xsl:variable name="currentID" select="substring-after(@target,'#')"/>
George
George Cristian Bina
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