cancel
Showing results for 
Search instead for 
Did you mean: 

how to include another XSL file?

tak
Champ in-the-making
Champ in-the-making
I have some trouble to use alfresco WCM 2.0.

I would like to make an XSL template including another XSL files,
however I couldn't produce desired HTML file.

What I wrote in XSL is like that.

<xsl:include href="/menu_fragment.xsl" /> <!– (1) –>

<xsl:variable name="t" select="document('/aaa.xml')"/> <!– (2) –>
<xsl:apply-templates select="$t/some_ns:menu" /> <!– (3) –>

(1) include another XSL template.
(2) bind another xml contents.
(3) apply template defined in (1) to bounded xml contents.

in (1), I tried these.
(a)I placed menu_fragment.xsl in web-project root folder.
(b) Same web forms space as this template.
© I tried <xsl:include href="${alf.parent_path}/aegif_menu_fragment.xsl" />

anyone knows how to describe XSL and where to place included XSL files?
:shock:
17 REPLIES 17

arielb
Champ in-the-making
Champ in-the-making
there were some issues with this which were addressed with WCM-399.  if you're on svn HEAD, then this should be working.  if not, it will be resolved in v2.0.1.

with the fix to 399, you can place the included template in either the data dictionary, or within the webapp.  however, xsl includes within the webapp should be working fine in all version.  if you're having issues, please turn up the debug levels and post the log output.

tak
Champ in-the-making
Champ in-the-making
Thank you!

That is exactly what I met.

I would have checked zilla first… sorry.

edgar
Champ in-the-making
Champ in-the-making
HI Ariel,

however, xsl includes within the webapp should be working fine in all version.

Can you maybe show me how to do this?

I have an XSL file in my web project. The AVM path to the file in my sandbox is:
V:\test–admin\HEAD\DATA\www\avm_webapps\ROOT\xsl\homepage_body.xsl

Now how do I include this file in my XSLT Template which is attached to my 'homepage' Web Form using an <xsl:include>?

Should I use ${alf.parent_path}?

I am currently running Alfresco 2.0 Community on Windows XP.

regards,

Edgar

arielb
Champ in-the-making
Champ in-the-making
include takes webapp relative paths, so <xs:include href="/path/within/webapp.xsl"/> should work.

edgar
Champ in-the-making
Champ in-the-making
Hi Ariel,

include takes webapp relative paths, so <xs:include href="/path/within/webapp.xsl"/> should work.

OK, cheers.

However it does not work for me.

In my "homepage_new_printable.xsl" I include another XSL like this:

<xsl:include href="/xsl/homepage_body.xsl"/>

This included XSL I have placed in my Web Project. The AVM path is:

V:\test–admin\HEAD\DATA\www\avm_webapps\ROOT\xsl\homepage_body.xsl

However what I get when I preview the JSP file that is generated from my homepage_new_printable.xsl I get a message:
error regenerating homepage_new2-printable.jsp using homepage_new_printable.xsl: null
in the Web Client and the following message in the console:
C:\Alfresco\dummy.xsl; Line #0; Column #0; Had IO Exception with stylesheet file: /xsl/homepage_body.xsl
file:///C:/Alfresco/dummy.xsl; Line #0; Column #0; javax.xml.transform.TransformerException: ElemTemplateElement error: homepage_body
12:05:15,007 ERROR [ui.common.Utils] error regenerating homepage_new2-printable.jsp using homepage_new_printable.xsl: null
java.lang.NullPointerException
        at org.alfresco.web.forms.XSLTRenderingEngine.render(XSLTRenderingEngine.java:411)

You stated:
ihowever, xsl includes within the webapp should be working fine in all version.

but it does not seem to be working for me on Alfresco Community 2.0?

regards,

Edgar

tak
Champ in-the-making
Champ in-the-making
It does not work for me yet…

The same exception has occurred as edger.
I tried both alfresco community edition 2.0 and enterprise edition 2.0.1.

Do we have to satisfy some format or specification about included XSL?

FYI
document function in XSL works fine by relative path.

regards

arielb
Champ in-the-making
Champ in-the-making
is your virtualization server up and running?  this is necessary for xsl:includes to work.  if it is, then the debugging information should be emitting messages as to which urls it's trying for to resolve the include.  if you're still having troubles, could you attach more of the debugging output please?

tak
Champ in-the-making
Champ in-the-making
I tried by output debugging log, but the flood of ehcache log froze the web  browser so i cannot check how alfresco resolves uri.
Would you tell me which log4j logger should i turn to debug? (xform?)

is your virtualization server up and running?  this is necessary for xsl:includes to work.  if it is, then the debugging information should be emitting messages as to which urls it's trying for to resolve the include.  if you're still having troubles, could you attach more of the debugging output please?

these are my test  files.
I put included.xsl and included.xml to the root space of web projects and
I regiseter including xsd and xsl as Web Forms.

including xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:sample="http://sample.org"
           targetNamespace="http://sample.org"
           elementFormDefault="qualified">
  
   <xs:element name="including">
     <xs:complexType>
        <xs:sequence>
           <xs:element name="title" type="xs:string" />
        </xs:sequence>
     </xs:complexType>
</xs:element>
      
</xs:schema>

including xsl

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
      xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:sample="http://sample.org"
      xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
      exclude-result-prefixes="xhtml xalan xsl fn">
  <xsl:output method="xml"  encoding="UTF-8" indent="yes"
              doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
              omit-xml-declaration="yes"
              media-type="text/html"/>

  <xsl:preserve-space elements="*"/>

<xsl:include href="/included.xsl" />

  <xsl:template match="/">

<html>

<head>
<title><xsl:value-of select="/sample:including/sample:title" /></title>
</head>

<body>
  <h1><xsl:value-of select="/sample:including/sample:title" /></h1>

  <xsl:variable name="t" select="document('/included.xml')"/> 
  <xsl:apply-templates select="$t/sample:menu" />

</body>
</html>
  </xsl:template>
</xsl:stylesheet>

included xsl

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
      xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:sample="http://sample.org"
      xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
      exclude-result-prefixes="xhtml xalan xsl sample fn">
  <xsl:output method="xml"  encoding="UTF-8" indent="yes"
              doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
              omit-xml-declaration="yes"
              media-type="text/html"/>

  <xsl:preserve-space elements="*"/>

  <xsl:template match="sample:menu">

<ul>
<xsl:for-each select="sample:menuItem">
  <li>
   
       <xsl:value-of select="sample:itemUrl"/>
       <xsl:value-of select="sample:itemName"/>
  </li>
</xsl:for-each>
</ul>

  </xsl:template>
</xsl:stylesheet>

included xml

<?xml version="1.0" encoding="UTF-8"?>
<sample:menu xmlns:sample="http://sample.org">

<sample:menuItem><sample:itemName>page1</sample:itemName>
  <sample:itemUrl>page1.html</sample:itemUrl>
</sample:menuItem>

<sample:menuItem>
  <sample:itemName>page2</sample:itemName><sample:itemUrl>/page2.html</sample:itemUrl>
</sample:menuItem>

<sample:menuItem>
<sample:itemName>page3</sample:itemName><sample:itemUrl>/page3.html</sample:itemUrl>
</sample:menuItem>

</sample:menu>
[/img]

kvc
Champ in-the-making
Champ in-the-making
Tak:


We'll look into this … our lead developer here in on holiday through July 4th and … if you are a customer or partner, please raise a support ticket and we can get one of our support engineers to look into in the meantime.


Kevin