RE: [xsl] document() function - unknown protocol

Subject: RE: [xsl] document() function - unknown protocol
From: "Robert Koberg" <rob@xxxxxxxxxx>
Date: Tue, 14 Oct 2003 18:23:03 -0700
No problem,

I am generally surprised it is not a more generally proposed solution (most
likely because it is java based -- JAXP). It is pretty simple.

There is a very simple way to implement it. I will point you to read:
http://xml.apache.org/commons/components/resolver/index.html
There are more complex ways that some of us need, but this should suffice.

But basically (in a simplistic way) all you need to do is pass some kind of
Map (key=value, or in other words href=resolvable_custom_uri) or an object
that holds the Map to the resolver. So this:

tFactory.setURIResolver(new MyResolver(""));

could be:

tFactory.setURIResolver(new MyResolver(myProject));

and the URIResolver can look like:

public class MyResolver implements URIResolver
{
  private Project project;

  public MyResolver ( Project _project )
  {
    this.project = _project;
  }

  public Source resolve( String href, String base )
  {
    Source source  = null;
    try {
      source = new StreamSource( this.project.someLookup( href ).getURL() );
    }
    catch ( Exception e ) {
      ...
    }
    if ( null == source )
      source = new StreamSource( new StringReader( "<error/>" ) );

    return source;
  }
}

Best,
-Rob





> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-
> list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jim Nachlin
> Sent: Tuesday, October 14, 2003 5:44 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> 
> Thanks for your suggestion.  As I understand it, the "arg:" is
> a sort of custom uri.  Still, it is not clear what it should
> be resolving to.
> 
> Any advice on how to do the custom uri resolver, or how to
> remove these "arg:" custom uris?
> 
> -Jim
> 
> P.S. so far, it's like this:
> 
>   TransformerFactory tFactory =
>        TransformerFactory.newInstance();
>   Source stylesheet = new StreamSource(xsl_file);
> 
>   tFactory.setURIResolver(new MyResolver("")); //confusing bit
>   Transformer transformer = tFactory.newTransformer(stylesheet);
>   StreamSource strs= new StreamSource(xml_file);
>   StreamResult strr=new StreamResult(new FileOutputStream(out_file));
>   transformer.transform(strs, strr);
> 
> 
> On Tue, 14 Oct 2003, Robert Koberg wrote:
> 
> > Hi,
> >
> > You need to set up a custom javax.xml.transform.URIResolver (assuming
> you
> > are using java). You will be passed two arguments when the resolve
> method is
> > automatically called when you use document(href [, base]). The first one
> is
> > the string you can use to resolve your custom URI.
> >
> > Best,
> > -Rob
> >
> >
> > > -----Original Message-----
> > > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-
> > > list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jim Nachlin
> > > Sent: Tuesday, October 14, 2003 10:22 AM
> > > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> > >
> > > Hi List,
> > >
> > > I hope that this is an appropriate question for this list.
> > >
> > > In trying to process an RDF foaf document [1] using the
> > > stylesheet [2], the processor, which is members of the
> > > javax.xml.transform package, gives an error which tells me that
> > > the protocol "arg" is unknown in this statement:
> > >
> > > <xsl:when test="document('arg:/ifp')/*/*/*">
> > >   <xsl:variable name="ifp">
> > >     <xsl:copy-of select="document('arg:/ifp')/*[1]/*[1]/*[1]"/>
> > >   </xsl:variable>
> > >   <xsl:apply-templates mode="output"  ...   />
> > > </xsl:when>
> > >
> > > or
> > >
> > > <xsl:variable name="def"
> > >
> > >
> select="document('arg:/schema')/ns/schema[@ns=$ns]/rdf:RDF/*[@rdf:about=$t
> > > his or @rdf:ID=$name or @ID=$name]"/>
> > >
> > > and in several other places.
> > >
> > > In looking over the documentation on document(), there is no
> > > mention of a protocol "arg" or what this could possibly be.  It
> > > seems that the stylesheet is trying to refer to one of the
> > > namespace URIs.
> > >
> > > Refs:
> > > [1] http://www.nachlin.com/foaf.rdf
> > > [2] http://xml.mfd-consult.dk/foaf/explorer/explorer.xsl
> > >
> > > Thanks in advance for helping an XSL noob.
> > >
> > > Jim
> > >
> > >
> > >
> > >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >
> >
> >  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread