Page 1 of 1

Dynamic xi:include/xpointer resolution

Posted: Thu Dec 11, 2008 6:36 am
by mflat
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

Code: Select all

<xi:include href="master-biblio.xml" xpointer="{$currentID}"/>
in "3. XSL transform" below.

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>
2. Master bibliography file to be referenced/processed for fragment inclusion (master-biblio.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>
<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>
3. XSL transform (transform.xsl):

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>
4. Desired output (desired-output.xml):

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

Re: Dynamic xi:include/xpointer resolution

Posted: Thu Dec 11, 2008 2:00 pm
by sorin_ristache
Hello,
mflat wrote:My problem seems to occur at the line

Code: Select all

<xi:include href="master-biblio.xml" xpointer="{$currentID}"/>
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:

Code: Select all

<xsl:copy-of select="doc('master-biblio.xml')//*[@xml:id=$currentID]"/>

Regards,
Sorin

Re: Dynamic xi:include/xpointer resolution

Posted: Fri Dec 12, 2008 2:47 am
by mflat
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,

Code: Select all

<xsl:copy-of select="document('master-biblio.xml')//*[@xml:id=$currentID]"/>
doesn't seem to work. (N.B.: changed "doc()" to "document()")

But if I substitute a literal value, e.g.

Code: Select all

<xsl:copy-of select="document('master-biblio.xml')//*[@xml:id='this']"/>
I get the desired result.

What am I missing?

Thank you very much!

Markus

Re: Dynamic xi:include/xpointer resolution

Posted: Fri Dec 12, 2008 6:18 pm
by george
Hi Markus,

The problem is here:

Code: Select all


<xsl:variable name="currentID" select="substring-after('@target','#')"/>
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

Code: Select all


<xsl:variable name="currentID" select="substring-after(@target,'#')"/>
Best Regards,
George

Re: Dynamic xi:include/xpointer resolution

Posted: Fri Dec 12, 2008 6:25 pm
by mflat
Oh my. I had a feeling it was going to be something silly like that.

Sorry about that, and thank you for pointing it out to me!

Markus