Including a Static XSD in a Web Form
Since their inception, Alfresco WCM Web Forms have supported an inclusion mechanism based on the standard XML Schema include and import constructs. Originally this mechanism read the included assets from the Web Project where the user was creating the content, but since v2.2SP3 the preferred mechanism has been to reference a Web Script instead (in fact the legacy mechanism may be deprecated in a future release).
One question that this new approach raises is how to support inclusion of static XSDs, as Web Scripts are inherently dynamic and introduce some unnecessary overhead for the simple static case. The good news is that Alfresco ships with a Web Script that simply reads a file from the repository and returns its contents:
/api/path/content{property}/{store_type}/{store_id}/{path}?a={attach?}
An example usage is:
/api/path/content/workspace/SpacesStore/Company Home/Data Dictionary/Presentation Templates/readme.ftl
Using the Web Script inclusion mechanism for Web Forms, we can use this Web Script to include or import any XSD file stored in the DM repository. For example, if we have a file called “my-include.xsd” in the “Company Home” space that contains the following content:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:alf="http://www.alfresco.org/"
targetNamespace="http://www.alfresco.org/"
elementFormDefault="qualified">
<xs:complexType abstract="true" name="IncludedComplexType">
<xs:sequence>
<xs:element name="Title"
type="xs:normalizedString"
minOccurs="1"
maxOccurs="1" />
<xs:element name="Summary"
type="xs:string"
minOccurs="0"
maxOccurs="1" />
<xs:element name="Keyword"
type="xs:normalizedString"
minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:schema>
We could include it into a Web Form XSD using an include statement such as the following:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:alf="http://www.alfresco.org/"
targetNamespace="http://www.alfresco.org/"
elementFormDefault="qualified">
<xs:include schemaLocation=”webscript://api/path/content/workspace/SpacesStore/Company Home/my-include.xsd?ticket={ticket}” />
<xs:complexType name=”MyWebFormType”>
<xs:complexContent>
<xs:extension base=”alf:IncludedComplexType”>
<xs:sequence>
<xs:element name=”Body”
type=”xs:string”
minOccurs=”1″
maxOccurs=”1″ />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name=”MyWebForm” type=”alf:MyWebFormType” />
</xs:schema>
This is clearly faster and easier than developing a custom Web Script to either emit the XML Schema shown above, or to return the contents of a specific XSD file from the repository!
This approach also provides a solution to another question: how does one neatly package up a Web Form, along with all of its dependencies, ready for deployment to another Alfresco environment?
By storing included XSD files in Company Home > Data Dictionary > Web Forms, we give ourselves the option to package up the entire Web Forms space as an ACP file and deploy that ACP file to any other Alfresco environment, knowing that we’ve captured not only all of the Web Forms in the source environment, but all dependent XSD files as well.
Tags: web forms, xml schema, xsd

July 14th, 2009 at 8:45 pm
Hi,
I tried this and its working for xsd schema.
But when I try to use the same pattern in xsl:import to import global xsl templates for the web forms it doesnt work.
I am adding this to the xsl that is associated to the web form
I also tried include
It gives error
Error generating rendition using Global_CRCnetBASE_landing_page.xsl: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: ElemTemplateElement error: substring-after-last
July 15th, 2009 at 5:19 am
Kalpesh, xsl:imports aren’t available from within XSL-backed renditioning templates but that would make a good enhancement request. I would also encourage you to investigate Freemarker-backed renditioning templates, as it’s a more flexible templating language and (via a forge project) supports inclusion of Web Scripts.
August 5th, 2009 at 1:32 pm
Including the webscripts in webform,
It will work only with the xsd files ? as we have here in the example including my-include.xsd (or) else we can also add webscripts which has *.xml file and response template *.ftl (or) /sample/ - webscript url, which one do we need to specify in the include to get the webscripts in webforms?
August 5th, 2009 at 5:32 pm
Saran, you can xs:include or xs:import the response from any Web Script, including custom Web Scripts that dynamically generate XSD. The only requirement is that the output from the Web Script is a valid XML Schema - that’s a requirement of the xs:include / xs:import mechanisms.
And just to clarify, this blog post illustrates the simpler use case of xs:including or xs:importing a static XSD file, without having to develop a custom Web Script (as a Web Script suitable for this purpose is included in Alfresco). It should be straight forward to extrapolate the custom Web Script use case from this example however, as the only additional moving part is the custom Web Script (and Web Script development is documented in detail elsewhere).
August 13th, 2009 at 2:41 pm
This is very useful for an XSD standpoint , I’ve used webscripts to populate dynamic XSDs, and they seemed to work very well.
Is there a way to call webscripts within an XSL file also?
August 13th, 2009 at 3:01 pm
agibson, as I mentioned to Kalpash:
August 13th, 2009 at 5:12 pm
Oops , thanks for the info , Here is what I found , http://forge.alfresco.com/scm/?group_id=211
Having trouble with the anonymous access of the subversion repository though is it still available?
August 13th, 2009 at 6:41 pm
Yeah I have a vague recollection that the forge doesn’t allow anonymous SVN checkouts (despite suggesting that they are allowed). It’s free to register though, so I’d suggest registering and seeing if you can checkout then.
August 14th, 2009 at 4:50 am
Peter , do you have any examples of using the Freemarker WSI , i.e proper syntax to include webscript , also I’ve added the freemarker wsi to my alfresco.war , but don’t really know where to go from there. Any help appreciated
August 14th, 2009 at 6:25 pm
agibson, there’s an example included in the source code on the forge project.
August 21st, 2009 at 7:05 pm
Thanks Peter,
Sorry, I visited this page after a month time.
Thanks for all the good work and creative samples that help us to reuse it in projects.
September 1st, 2009 at 2:35 pm
Just to report back on some of my findings , I did get the Freemarker WSI project to work with a simple freemarker page and webscript, considering I am on 3.1 there were a few updates to the java code and spring configuration to get it all working …..It did not however work for XSL inclusion in Web forms, and I haven’t had time to figure out exactly why.
September 1st, 2009 at 8:09 pm
agibson, the Freemarker WSI project is not intended to provide an inclusion mechanism for XSL templates - its sole purpose is to provide a way to include the output from a Web Script in a Freemarker template.
September 2nd, 2009 at 3:10 pm
Sorry I mispoke , I meant to say ….
*It did not however work for Freemarker template inclusion in Web forms, and I haven’t had time to figure out exactly why.
September 2nd, 2009 at 8:08 pm
Ah ok. Do you have an account on the Alfresco forge? If so let me know what it is and I’ll add you as a committer to the freemarker-wsi project so that if/when you find out what’s breaking you can commit your changes.
September 3rd, 2009 at 2:08 pm
Hi Peter ,
The WSI is working in Web Scripts , but it does not appear to work in Web forms. I have updated the code to work with Enterprise 3.1 , if you want to create a branch I can commit to it …. my Alfresco forge accout is agibson
September 24th, 2009 at 10:23 am
Hi Peter,
I’m attempting to have a XSD use this method to include a XSD that, itself has includes. That second include isn’t working.
Thoughts on whether trying to build something like that is a good idea or bad idea?
Thanks,
Karl
October 27th, 2009 at 4:17 pm
Thank you so much for this info Peter. Very useful!!