You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by David Fishburn <fi...@ianywhere.com> on 2003/07/17 19:42:28 UTC

Xsl:include support?

Xalan 1.5
Xerces 2.2.0
WinXP
VC6 sp5

I am converting our code from Java Xalan to C++ Xalan.
One of the things we use on every page is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
    <xsl:value-of select="data"/>
  </xsl:template>
  <xsl:include href="/xsl?name=genericHead.xsl"/>
</xsl:stylesheet>

Specifically:
  <xsl:include href="/xsl?name=genericHead.xsl"/>

For Java Xalan, I had to create a XSLTURIResolver.java.
When a xsl:include is found, the resolver tells xalan how to find the
genericHead.xsl document.

Is this supported in the C++ Xalan?  
I have looked around the C++ API docs, but it is quite different than
the Java version.

Is there a sample that does this?
I grepped through the sample directory for this, but couldn't find
anything.

When I tried it:

XalanTransform.exe generic.xml generic.xsl

XSLT warning: Fatal Error at (file <unknown>, line 0, column 0): An
exception oc
curred! Type:RuntimeException, Message:The primary document entity could
not be
opened.
Id=file:///C:/OpenSrc/xalan/C/xml-xalan/c/samples/XalanTransform//xsl?na
me=genericHead.xsl (generic.xsl, line 7, column 50)
Error: SAXParseException: An exception occurred! Type:RuntimeException,
Message:
The primary document entity could not be opened.
Id=file:///C:/OpenSrc/xalan/C/x
ml-xalan/c/samples/XalanTransform//xsl?name=genericHead.xsl (, line 0,
column 0)

  <xsl:include href="/xsl?name=genericHead.xsl"/>

It could be the format of the include, in this case it had to go to
http://localhost/xsl to retrieve the XSL.

TIA,
Dave


Here were the 2 files I used:
generic.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
    <xsl:value-of select="data"/>
  </xsl:template>
  <xsl:include href="/xsl?name=genericHead.xsl"/>
</xsl:stylesheet>

generic.xml
<?xml version="1.0" encoding="UTF-8"?>
<data>This is a test!</data>



RE: Xsl:include support - how to enable it?

Posted by David Fishburn <fi...@ianywhere.com>.
Much appreciated Mark, I have everything working as I need now.

Now I have to run some speed tests between the Java version and the C++
version.

Java is usually 10 times slower, so I am expecting to get some large
percentage.

Has anyone done this type of comparision already?

Thanks,
Dave

-----Original Message-----
From: Mark Weaver [mailto:mark@npsl.co.uk] 
Sent: Tuesday, July 29, 2003 12:36 PM
To: xalan-c-users@xml.apache.org
Subject: RE: Xsl:include support - how to enable it?


Here is a modified version that defines and installs an EntityResolver.
You will need to modify the resolver to suit; this one just returns a
URLInputSource for the URL:

class MyResolver : public EntityResolver {
public:
	InputSource* resolveEntity (const XMLCh* const publicId,
                                const XMLCh* const systemId)
	{
		XMLURL URL(systemId);
		return new URLInputSource(URL);
	}
};

Any rewriting that you want to take place can be performed on the URL
object.

> -----Original Message-----
> From: David Fishburn [mailto:fishburn@ianywhere.com]
> Sent: 29 July 2003 16:05
> To: 'Mark Weaver'; xalan-c-users@xml.apache.org
> Subject: RE: Xsl:include support - how to enable it?
>
>
>
> Right, but where (what directory), do I create this class in: entity 
> resolver class.
>
> Then what do I need to recompile to enable it?
>
> Thanks,
> Dave
>
> -----Original Message-----
> From: Mark Weaver [mailto:mark@npsl.co.uk]
> Sent: Monday, July 28, 2003 8:52 AM
> To: xalan-c-users@xml.apache.org
> Subject: RE: Xsl:include support - how to enable it?
>
>
>
> > After that, I am not sure how to enable the EntityResolver. I am 
> > using the following sample that I have based everything on: 
> > C:\OpenSrc\xalan\C\xml-xalan\c\samples\XalanTransformerCallback
> >
> > So I am not sure where I need to put the code to enable this. I am 
> > putting it in my XalanTransformaterCallback.cpp file?
> >
> >
> You just need to call XalanTransformer::setEntityResolver with a 
> pointer to your entity resolver class.
>
> Mark
>
>
>
>


RE: Xsl:include support - how to enable it?

Posted by da...@us.ibm.com.



Hi Dave,

dumpbin.exe is your friend!

   dumpbin /exports <filename>

   dumpbin /imports <filename>

Do a dumpbin without any arguments for more info.

Dave



                                                                                                                                          
                      "David Fishburn"                                                                                                    
                      <fishburn@ianywh         To:      <xa...@xml.apache.org>                                                    
                      ere.com>                 cc:      (bcc: David N Bertoni/Cambridge/IBM)                                              
                                               Subject: RE: Xsl:include support - how to enable it?                                       
                      08/06/2003 07:07                                                                                                    
                      PM                                                                                                                  
                                                                                                                                          



> My copy of Xalan-C_1_6_0D.dll _does_ contain the following symbol:
>
?setEntityResolver@XalanTransformer@xalanc_1_6@@QAEXPAVEntityResolver@xe
rcesc_2_3@@@Z

By the way, what tool did you use to find that you had that symbol?
I can't figure out which Microsoft utility will list the symbols in a
debug lib/dll.

Thanks,
Dave




RE: Xsl:include support - how to enable it?

Posted by David Fishburn <fi...@ianywhere.com>.
> My copy of Xalan-C_1_6_0D.dll _does_ contain the following symbol:
>
?setEntityResolver@XalanTransformer@xalanc_1_6@@QAEXPAVEntityResolver@xe
rcesc_2_3@@@Z

By the way, what tool did you use to find that you had that symbol?
I can't figure out which Microsoft utility will list the symbols in a
debug lib/dll.

Thanks,
Dave


RE: Xsl:include support - how to enable it?

Posted by da...@us.ibm.com.



Hi Dave,

You should double-check to make sure you changed all of the relevant
settings and that everything has been rebuilt properly.

XalanTransformer::setEntityResolver() is an inline function, so the release
build will not contain the symbol.  In a debug build, the compiler will
likely generate an out-of-line copy, so you may have to change what
libraries you link against.  My copy of Xalan-C_1_6_0D.dll _does_ contain
the following symbol:

   ?setEntityResolver@XalanTransformer@xalanc_1_6@@QAEXPAVEntityResolver@xercesc_2_3@@@Z

Dave



                                                                                                                                  
                      "David Fishburn"                                                                                            
                      <fishburn@ianywh         To:      <xa...@xml.apache.org>                                            
                      ere.com>                 cc:      (bcc: David N Bertoni/Cambridge/IBM)                                      
                                               Subject: RE: Xsl:include support - how to enable it?                               
                      08/06/2003 10:15                                                                                            
                      AM                                                                                                          
                                                                                                                                  




I just upgraded to Xalan 1.6 and Xerces 2.3.0
WinXP
VC 6 sp5

Besides changing the location of a couple of includes, I can
successfully build a Release version of my project.

I get compiler errors when I try to compile the Debug version of my
Project though:

Linking...
   Creating library Debug/xalan16trans.lib and object
Debug/xalan16trans.exp
extXalandll.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: void __thiscall
xalanc_1_6::XalanTransformer::setEntityResolver(class
xercesc_2_3::EntityResolver *)"
(__imp_?setEntityResolver@XalanTransformer@xalanc_1_6@@Q
AEXPAVEntityResolver@xercesc_2_3@@@Z)


Some relevant points:
I have recompiled the XercesLib project for both Win32 Release and Win32
Debug.
These successfully compiled.

I copied the lib (release and debug) to the:
xerces-c_2_3_0-win32\lib

I copied the DLL (release and debug) to the:
xerces-c_2_3_0-win32\bin


Thanks,
Dave




-----Original Message-----
From: Mark Weaver [mailto:mark@npsl.co.uk]
Sent: Tuesday, July 29, 2003 12:36 PM
To: xalan-c-users@xml.apache.org
Subject: RE: Xsl:include support - how to enable it?


Here is a modified version that defines and installs an EntityResolver.
You will need to modify the resolver to suit; this one just returns a
URLInputSource for the URL:

class MyResolver : public EntityResolver {
public:
             InputSource* resolveEntity (const XMLCh* const publicId,
                                const XMLCh* const systemId)
             {
                         XMLURL URL(systemId);
                         return new URLInputSource(URL);
             }
};

Any rewriting that you want to take place can be performed on the URL
object.




RE: Xsl:include support - how to enable it?

Posted by David Fishburn <fi...@ianywhere.com>.
I just upgraded to Xalan 1.6 and Xerces 2.3.0 
WinXP
VC 6 sp5

Besides changing the location of a couple of includes, I can
successfully build a Release version of my project.

I get compiler errors when I try to compile the Debug version of my
Project though:

Linking...
   Creating library Debug/xalan16trans.lib and object
Debug/xalan16trans.exp
extXalandll.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: void __thiscall
xalanc_1_6::XalanTransformer::setEntityResolver(class
xercesc_2_3::EntityResolver *)"
(__imp_?setEntityResolver@XalanTransformer@xalanc_1_6@@Q
AEXPAVEntityResolver@xercesc_2_3@@@Z)


Some relevant points:
I have recompiled the XercesLib project for both Win32 Release and Win32
Debug.
These successfully compiled.

I copied the lib (release and debug) to the:
xerces-c_2_3_0-win32\lib

I copied the DLL (release and debug) to the:
xerces-c_2_3_0-win32\bin


Thanks,
Dave




-----Original Message-----
From: Mark Weaver [mailto:mark@npsl.co.uk] 
Sent: Tuesday, July 29, 2003 12:36 PM
To: xalan-c-users@xml.apache.org
Subject: RE: Xsl:include support - how to enable it?


Here is a modified version that defines and installs an EntityResolver.
You will need to modify the resolver to suit; this one just returns a
URLInputSource for the URL:

class MyResolver : public EntityResolver {
public:
	InputSource* resolveEntity (const XMLCh* const publicId,
                                const XMLCh* const systemId)
	{
		XMLURL URL(systemId);
		return new URLInputSource(URL);
	}
};

Any rewriting that you want to take place can be performed on the URL
object.


RE: Xsl:include support - how to enable it?

Posted by Mark Weaver <ma...@npsl.co.uk>.
Here is a modified version that defines and installs an EntityResolver.  You
will need to modify the resolver to suit; this one just returns a
URLInputSource for the URL:

class MyResolver : public EntityResolver {
public:
	InputSource* resolveEntity (const XMLCh* const publicId,
                                const XMLCh* const systemId)
	{
		XMLURL URL(systemId);
		return new URLInputSource(URL);
	}
};

Any rewriting that you want to take place can be performed on the URL
object.

> -----Original Message-----
> From: David Fishburn [mailto:fishburn@ianywhere.com]
> Sent: 29 July 2003 16:05
> To: 'Mark Weaver'; xalan-c-users@xml.apache.org
> Subject: RE: Xsl:include support - how to enable it?
>
>
>
> Right, but where (what directory), do I create this class in:
> entity resolver class.
>
> Then what do I need to recompile to enable it?
>
> Thanks,
> Dave
>
> -----Original Message-----
> From: Mark Weaver [mailto:mark@npsl.co.uk]
> Sent: Monday, July 28, 2003 8:52 AM
> To: xalan-c-users@xml.apache.org
> Subject: RE: Xsl:include support - how to enable it?
>
>
>
> > After that, I am not sure how to enable the EntityResolver.
> > I am using the following sample that I have based everything on:
> > C:\OpenSrc\xalan\C\xml-xalan\c\samples\XalanTransformerCallback
> >
> > So I am not sure where I need to put the code to enable this. I am
> > putting it in my XalanTransformaterCallback.cpp file?
> >
> >
> You just need to call XalanTransformer::setEntityResolver with a pointer
> to your entity resolver class.
>
> Mark
>
>
>
>

RE: Xsl:include support - how to enable it?

Posted by David Fishburn <fi...@ianywhere.com>.
Right, but where (what directory), do I create this class in: 
entity resolver class.

Then what do I need to recompile to enable it?

Thanks,
Dave

-----Original Message-----
From: Mark Weaver [mailto:mark@npsl.co.uk] 
Sent: Monday, July 28, 2003 8:52 AM
To: xalan-c-users@xml.apache.org
Subject: RE: Xsl:include support - how to enable it?



> After that, I am not sure how to enable the EntityResolver.
> I am using the following sample that I have based everything on: 
> C:\OpenSrc\xalan\C\xml-xalan\c\samples\XalanTransformerCallback
>
> So I am not sure where I need to put the code to enable this. I am 
> putting it in my XalanTransformaterCallback.cpp file?
>
>
You just need to call XalanTransformer::setEntityResolver with a pointer
to your entity resolver class.

Mark



RE: Xsl:include support - how to enable it?

Posted by Mark Weaver <ma...@npsl.co.uk>.
> After that, I am not sure how to enable the EntityResolver.
> I am using the following sample that I have based everything on:
> C:\OpenSrc\xalan\C\xml-xalan\c\samples\XalanTransformerCallback
>
> So I am not sure where I need to put the code to enable this.
> I am putting it in my XalanTransformaterCallback.cpp file?
>
>
You just need to call XalanTransformer::setEntityResolver with a pointer to
your entity resolver class.

Mark


RE: Xsl:include support - how to enable it?

Posted by David Fishburn <fi...@ianywhere.com>.
Thanks for the response Mark.

I am new to all of this.
I read through the API documentation for the EntityResolver
(http://xml.apache.org/xerces-c/apiDocs/classEntityResolver.html).
It looks like it will do what I need it to.
In fact the sample code in the doc has:
****************
  *#include <xercesc/sax/EntityResolver.hpp>
  *#include <xercesc/sax/InputSource.hpp>

  *class MyResolver : public EntityResolver {
  public:
    InputSource resolveEntity (const XMLCh* const publicId,
                               const XMLCh* const systemId);
   ...
   };

  MyResolver::resolveEntity {
    if (XMLString::compareString(systemId,
"http://www.myhost.com/today")) {
      MyReader* reader = new MyReader();
      return new InputSource(reader);
    } else {
      return null;
    }
  }
****************

I would need:
    if (XMLString::compareString(systemId, "http://localhost")) {


Where this breaks down though, is what are the detailed steps that I
need to follow to set this up.

Assuming I have Xerces 2.2.0 installed at:
C:\OpenSrc\xalan\C\xerces-c2_2_0-win32

And Xalan 1.5 at:
C:\OpenSrc\xalan\C\xml-xalan

What file do I need to create and in what directory to add this
override.
Does anyone have a complete .cpp code snippet that I can use.

Once I create this file, I assume I will have to rebuild my Xerces DLLs
(no problem).

After that, I am not sure how to enable the EntityResolver.
I am using the following sample that I have based everything on:
C:\OpenSrc\xalan\C\xml-xalan\c\samples\XalanTransformerCallback

So I am not sure where I need to put the code to enable this.
I am putting it in my XalanTransformaterCallback.cpp file?


If someone could provide me a bit of direction (and code if you can!)
here I would greatly appreciate it.


Right now I have everything working as I need it, but I am actually
copying the xsl:templates directly into the documents instead of using
the xsl:include tags.


Thanks,
Dave



-----Original Message-----
From: Mark Weaver [mailto:mark@npsl.co.uk] 
Sent: Friday, July 18, 2003 1:27 PM
To: xalan-c-users@xml.apache.org
Subject: RE: Xsl:include support?


>
> > Specifically:
> >   <xsl:include href="/xsl?name=genericHead.xsl"/>
> >
> > For Java Xalan, I had to create a XSLTURIResolver.java. When a 
> > xsl:include is found, the resolver tells xalan how to find the 
> > genericHead.xsl document.
> >
> > Is this supported in the C++ Xalan?
> > I have looked around the C++ API docs, but it is quite different 
> > than the Java version.
>
> Xalan-C++ does not have the concept of a URIResolver.  There have been
> requests, but not enough resources to design and implement it.
>
There is an EntityResolver though -- you can create one of these and
provide an appropriate InputSource object.  (These are Xerces objects,
so those are the docs you want to look at)

mARK



RE: Xsl:include support?

Posted by Mark Weaver <ma...@npsl.co.uk>.
>
> > Specifically:
> >   <xsl:include href="/xsl?name=genericHead.xsl"/>
> >
> > For Java Xalan, I had to create a XSLTURIResolver.java.
> > When a xsl:include is found, the resolver tells xalan how to find the
> > genericHead.xsl document.
> >
> > Is this supported in the C++ Xalan?
> > I have looked around the C++ API docs, but it is quite different than
> > the Java version.
>
> Xalan-C++ does not have the concept of a URIResolver.  There have been
> requests, but not enough resources to design and implement it.
>
There is an EntityResolver though -- you can create one of these and provide
an appropriate InputSource object.  (These are Xerces objects, so those are
the docs you want to look at)

mARK


Re: Xsl:include support?

Posted by da...@us.ibm.com.



> Specifically:
>   <xsl:include href="/xsl?name=genericHead.xsl"/>
>
> For Java Xalan, I had to create a XSLTURIResolver.java.
> When a xsl:include is found, the resolver tells xalan how to find the
> genericHead.xsl document.
>
> Is this supported in the C++ Xalan?
> I have looked around the C++ API docs, but it is quite different than
> the Java version.

Xalan-C++ does not have the concept of a URIResolver.  There have been
requests, but not enough resources to design and implement it.

Dave