Xinclude fragments

Questions about XML that are not covered by the other forums should go here.
rrliu
Posts: 37
Joined: Sun Feb 12, 2006 10:34 pm

Xinclude fragments

Post by rrliu »

I'm encountering problems "including" fragments of XSLT into XSLT using general entities of DTD with Xalan. Depending on the XSLT that a general entity resolves to, I get a NullPointerException, even though the same thing works when I use another XSLT engine. I hear -- but can find no confirmation on the Web -- that this has to do with Xalan precompiling XSLT. I've been able to narrow the problem XSLT down to fragments that contain xs:choose.

Question 1: Does anyone have more specific information on this problem and, if so, is there a solution or workaround?

In order to circumvent the problem, I'm trying to use Xinclude. My first attempt was to simple cut the contents of a general entity out, place it in a separate file, and replace it in the entity definition by an xi:include point to the file. Unfortunately, it seems that the document must be well formed, i.e., must have a root element. So I placed a root element xsl:stylesheet into the included xml and tried to use xpointer in xi:incloude to indicate that I only want the "guts", not the root element, e.g., xpointer="range-inside(element(/1))". It seems, unfortunately, that either XInclude or the parser being used by the XSLT engine (I've tried Saxon 6.5.5 and Xalan) don't allow range-inside.

Question 2: How can I use only a fragment of the XML document?

Here's what I have:

The XML document that needs the fragment:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY % wbml_xslt SYSTEM "wbml_xslt.ent">
%wbml_xslt;
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wbr="http://www.ubs.com/namespaces/wbml-render" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="wb2xhtml_0.0.xslt"/>
<xsl:import href="local/wbml_xslt_global.xslt"/>
&enter-stylesheet;
<xsl:variable name="_xsltversion">XSLT for Accessibility/wb2xhtml_0.0_local.xslt</xsl:variable>
<xsl:variable name="_markoftheweb">http://www.ubs.com/</xsl:variable>
</xsl:stylesheet>

In wbml_xslt:ent:

<!ENTITY enter-stylesheet "
<xi:include href='enter_stylesheet.xml' xpointer='range-inside(element(/1))' xmlns:xi='http://www.w3.org/2001/XInclude'/>
">

The XIncluded document enter_stylesheet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:param name="_dfltLang" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
<xsl:param name="_server" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltServer"/>
</xsl:param>
<xsl:param name="_imageservlet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltImageservlet"/>
</xsl:param>
<xsl:param name="_mediaservlet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltMediaservlet"/>
</xsl:param>
<xsl:param name="_chartservlet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltChartservlet"/>
</xsl:param>
<xsl:param name="_formserver" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltFormserver"/>
</xsl:param>
<xsl:param name="_formapplication" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltFormapplication"/>
</xsl:param>
<xsl:param name="_path" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltPath"/>
</xsl:param>
<xsl:param name="_siteRef" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of
select="wbr:renderingPage/@siteRef | wbr:renderingArticle/@siteRef | wbr:homepage/@siteRef"
/>
</xsl:param>
<xsl:param name="_nodeRef" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of
select="wbr:renderingPage/@nodeRef | wbr:renderingArticle/@nodeRef | wbr:homepage/@nodeRef"
/>
</xsl:param>
<xsl:param name="_pageId" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of
select="wbr:renderingPage/@pageId | wbr:renderingArticle/@pageRef | wbr:homepage/@pageId"
/>
</xsl:param>
<xsl:param name="_variantId" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of
select="wbr:renderingPage/@variantId | wbr:renderingArticle/@variantId | wbr:homepage/@variantId"
/>
</xsl:param>
<xsl:param name="_color" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of
select="wbr:renderingPage/@color | wbr:renderingArticle/@color | wbr:homepage/@color"/>
</xsl:param>
<xsl:param name="_textcolor" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of
select="wbr:renderingPage/@textcolor | wbr:renderingArticle/@textcolor | wbr:homepage/@textcolor"
/>
</xsl:param>
<xsl:param name="_transparency" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of
select="wbr:renderingPage/@transparency | wbr:renderingArticle/@transparency | wbr:homepage/@transparency"
/>
</xsl:param>
<xsl:param name="_navLang" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of
select="wbr:renderingPage/@navLang | wbr:renderingArticle/@navLang | wbr:homepage/@navLang"
/>
</xsl:param>
<xsl:param name="_articleId" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of select="wbr:renderingArticle/@articleId"/>
</xsl:param>
<xsl:param name="_channelRef" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of select="wbr:renderingArticle/@channelRef"/>
</xsl:param>
<xsl:param name="_accessibilityParms" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltAccessibilityParms"/>
</xsl:param>
<xsl:variable name="_accessibilityVisibleStructure"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of select="contains($_accessibilityParms, 'visible-structure')"/>
</xsl:variable>
<xsl:variable name="_accessibilityImagesInProse"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:value-of select="contains($_accessibilityParms, 'images-in-prose')"/>
</xsl:variable>
<xsl:variable name="_doclang" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wbr="http://www.ubs.com/namespaces/wbml-render">
<xsl:choose>
<xsl:when test="$_dfltLang != ''">
<xsl:value-of select="$_dfltLang"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/child::*[1]/@xml:lang"
xmlns:xml="http://www.w3.org/XML/1998/namespace"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform" match="/">
<xsl:param name="dfltLang" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_dfltLang"/>
</xsl:param>
<xsl:param name="siteRef" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_siteRef"/>
</xsl:param>
<xsl:param name="nodeRef" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_nodeRef"/>
</xsl:param>
<xsl:param name="pageId" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_pageId"/>
</xsl:param>
<xsl:param name="variantId" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_variantId"/>
</xsl:param>
<xsl:param name="color" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_color"/>
</xsl:param>
<xsl:param name="textcolor" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_textcolor"/>
</xsl:param>
<xsl:param name="transparency" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_transparency"/>
</xsl:param>
<xsl:param name="navLang" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_navLang"/>
</xsl:param>
<xsl:param name="articleId" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_articleId"/>
</xsl:param>
<xsl:param name="channelRef" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:value-of select="$_channelRef"/>
</xsl:param>
<xsl:variable name="lang" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
<xsl:choose>
<xsl:when test='@xml:lang'><xsl:value-of select='@xml:lang'/></xsl:when>
<xsl:otherwise><xsl:value-of select='$dfltLang'/></xsl:otherwise>
</xsl:choose>
-->
<xsl:variable name="_l" select="ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
<xsl:choose>
<xsl:when test="$_l">
<xsl:value-of select="$_l"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$dfltLang"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable> &apply-templates; </xsl:template>
</xsl:stylesheet>

Any solution should work with Saxon and Xalan.

Thanks,
Richard
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Xinclude fragments

Post by sorin_ristache »

Hello,
rrliu wrote:Depending on the XSLT that a general entity resolves to, I get a NullPointerException, even though the same thing works when I use another XSLT engine.
Can you post a sample ?
rrliu wrote:Question 2: How can I use only a fragment of the XML document?

Here's what I have:
Use the following XML document:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY wbml_xslt SYSTEM "wbml_xslt.ent">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wbr="http://www.ubs.com/namespaces/wbml-render" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="wb2xhtml_0.0.xslt"/>
<xsl:import href="local/wbml_xslt_global.xslt"/>
&wbml_xslt;
<xsl:variable name="_xsltversion">XSLT for Accessibility/wb2xhtml_0.0_local.xslt</xsl:variable>
<xsl:variable name="_markoftheweb">http://www.ubs.com/</xsl:variable>
</xsl:stylesheet>
wbml_xslt.ent should be:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xi:include href='enter_stylesheet.xml' xpointer='element(/1/1)' xmlns:xi='http://www.w3.org/2001/XInclude'/>
<xi:include href='enter_stylesheet.xml' xpointer='element(/1/2)' xmlns:xi='http://www.w3.org/2001/XInclude'/>
<xi:include href='enter_stylesheet.xml' xpointer='element(/1/3)' xmlns:xi='http://www.w3.org/2001/XInclude'/>

...

<xi:include href='enter_stylesheet.xml' xpointer='element(/1/23)' xmlns:xi='http://www.w3.org/2001/XInclude'/>
You have to enable XInclude processing in Options -> Preferences -> XML / XML Parser.

Regards,
Sorin
rrliu
Posts: 37
Joined: Sun Feb 12, 2006 10:34 pm

Post by rrliu »

In effect you're saying that the only way to include multiple nodes -- what I've called a fragment, because I want the children of the single root element -- is to use the element() scheme of XInclude to include each element specifically. I'm afraid that's too primitive to consider, as every change in the stuff I include would mean recounting.

More on the problem: I think the problem I'm experiencing with Xalan has to do with global variables and global parameters which calculate their values based on other global variables/parameters, but I can't be sure. Does this perhaps sound familiar? I'm trying to narrow things down, but in the meantime I would appreciate any hints that you can give. The NullPointerException is hardly any helpful -- too bad Xalan doesn't at least mention something in the source templates where it was when it raised the exception.

Regards,
Richard
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Richard,

If the NPE is in Xalan then it should not matter how the stylesheet was obtain, that is if you use entities or not in the stylesheet, or if you use XInclude to create it. You can test starting from your initial example (without XInclude) and replace the entity reference with the actual entity content and see if you get the exception again.
I remember I got a NPE with Xalan when I had an invalid XPath expression at some moment.
Also, do you get the exception also in oXygen? If you get the exception only from command line then you may use an old version of Xalan bundled with the JVM (Java 1.4 contained a buggy Xalan).

In any case XSLT has xsl:include and xsl:inport that are provided exactly for handling stylesheet modules and I would recommend using them instead of entities or XInclude. If that is not possible then use just entities.
Oxygen although has XInclude support does not enable it for processing XSLT stylesheet as we assume that XInclude elements are used inside XSLT to be generated in the output and not to XInclude XSLT fragments.

oXygen uses mainly Xerces for XInclude support (you can use also XMLINT/XSLTPROC from oXygen and that also has XInclude support) and Xerces has some limitations, see:
http://xerces.apache.org/xerces2-j/faq- ... html#faq-7
Note: "The XPointer xpointer() Scheme is currently not supported."

We may eventually help you better if you can post a cut down sample XML/XSLT to reproduce the problem.

Best Regards,
George
duanegran
Posts: 2
Joined: Mon Sep 18, 2006 3:46 pm

Post by duanegran »

george wrote:oXygen uses mainly Xerces for XInclude support (you can use also XMLINT/XSLTPROC from oXygen and that also has XInclude support) and Xerces has some limitations, see:
http://xerces.apache.org/xerces2-j/faq- ... html#faq-7
Note: "The XPointer xpointer() Scheme is currently not supported."
I've searched for forums and I see that I'm not alone in my desire to use XPointer and XInclude to draw in fragments from other documents. In my case I'm writing a DocBook and would like the convenience of pulling in code fragments and content via XPointer into my documentation.

From what I can tell others in the DocBook community consider this to be a routine exercise, but it doesn't appear possible in oXygen. I realize the limitation comes from the Xerces parser, but can you comment on ways to work around this? If necessary I don't mind stepping outside of oXygen for the transformation step, but I would prefer to work within oXygen.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,
duanegran wrote:
george wrote:oXygen uses mainly Xerces for XInclude support (you can use also XMLINT/XSLTPROC from oXygen and that also has XInclude support) and Xerces has some limitations, see:
http://xerces.apache.org/xerces2-j/faq- ... html#faq-7
Note: "The XPointer xpointer() Scheme is currently not supported."
...

can you comment on ways to work around this?
You can include using the XPointer scheme in <oXygen/>. Select the Xsltproc engine in the transformation scenario and enable XInclude for the Xsltproc engine which supports the XPointer scheme.


Regards,
Sorin
duanegran
Posts: 2
Joined: Mon Sep 18, 2006 3:46 pm

Post by duanegran »

sorin wrote:Hello,

You can include using the XPointer scheme in <oXygen/>. Select the Xsltproc engine in the transformation scenario and enable XInclude for the Xsltproc engine which supports the XPointer scheme.


Regards,
Sorin
Sorin,

Thank you much for the suggestion. I've tried this, but unfortunately it doesn't work, but maybe I'm not using XPointer correctly. Let me share my code below:

Code: Select all


<para>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
href="../../detail/tab-detail-view.xsl"
xpointer="xmlns(xforms=http://www.w3.org/2002/xforms)xpointer(//xforms:save-success)">
<xi:fallback>dummy text</xi:fallback>
</xi:include> is shown when the save operation succeeds.
</para>
Each time I run the transformation it uses my xi:fallback text instead of the content in the save-sucess element in the tab-detail-view.xsl document. Any suggestions you have on this are most welcome. I'm happy to share my full files in email if that is helpful.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

If the path "../../detail/tab-detail-view.xsl" is correct, there are save-success elements of the "http://www.w3.org/2002/xforms" namespace in tab-detail-view.xsl, both the XML input and the XSLT input are valid and you get the fallback text in the transformation result please send sample files for reproducing the error.


Regards,
Sorin
Post Reply