Re: [xslt] document() Function and Fragment Identifiers



Mark Gannon schrieb am 21.11.2010 um 16:01 (-0800):
> 
> I'm working on an xsl implementation that requires retrieving
> documents over the network using fragment identifiers.  By fragment
> identifiers I mean URLs that look like: 
> 
> http://www.truenorth.nu/goodstuff.xml#moregood
> 
> In this example everything after the "#" is the identifier for a node
> (e.g. an attribute where id="moregood").  From reading the
> documentation for libxslt and xsl (Tidwell's book) my understanding is
> that this should return the node with the "moregood" id and any
> children the node might have.
> 
> Is this an accurate understanding of how this should work?

Yes. But note that it doesn't work in all processors. Yes in LibXSLT and
Saxon, no in Xalan 2.7.1 and MSXML 6.0.

> If my understanding of how fragment identifiers should work is
> accurate, the following example is returning a null or empty set for a
> URL when using a fragment ID when I would expect to get a node set
> based on the id: 

What you appear to have yet to discover is that ID-ness in this case
is conferred upon element nodes in the document by virtue of their
carrying an attribute of type ID as per the *DTD*.

Here's a sample I have to demonstrate this:

          \,,,/
          (o o)
------oOOo-(_)-oOOo------           id-function.xml
<!DOCTYPE Urmel[
<!ELEMENT Urmel (Elm*,Schelm*)>
<!ELEMENT Elm EMPTY>
<!ATTLIST Elm AB ID #REQUIRED>
<!ELEMENT Schelm EMPTY>
<!ATTLIST Schelm ab IDREFS #REQUIRED>
]>
<Urmel>
  <Elm AB="Erwin"/>
  <Elm AB="Egon"/>
  <Elm AB="Eberhard"/>
  <Elm AB="Eduard"/>
  <Elm AB="Edmund"/>
  <Elm AB="Ewald">
    <mit-Inhalt/>
  </Elm>
  <Schelm ab="Erwin Egon Eberhard"/>
  <Schelm ab="Egon"/>
  <Schelm ab="Ewald Erwin"/>
</Urmel>

-------------------------           id-function.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:strip-space elements="*"/>
  <xsl:output indent="yes"/>

  <xsl:template match="/">
    <mit-ID>
      <via-id-Funktion>
        <xsl:apply-templates select="*/Schelm"/>
      </via-id-Funktion>
      <auch-via-URI>
        <xsl:copy-of select="document('id-function.xml#Ewald')"/>
      </auch-via-URI>
    </mit-ID>
  </xsl:template>

  <xsl:template match="Schelm">
    <xsl:copy>
      <xsl:copy-of select="id(@ab)"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

-- 
Michael Ludwig


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]