[opencms-dev] Information about content tool "Convert XML contents" ?
Mario Jäger
m.jaeger at alkacon.com
Wed Jun 22 10:33:58 CEST 2011
Hi Holger,
Yes, the output "Error while transformation." is not very meaningful.
But, this is improved in the current OpenCms head already. In case of an
error you get more information then.
Here is a little example how to use that tool.
(1) You have a test folder /sites/default/xmlkonv/ with the resource
photoalbum.html from resource type "photoalbum" with that xml content:
<?xml version="1.0" encoding="UTF-8"?>
<PhotoAlbumConfigurations
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum.xsd">
<PhotoAlbumConfiguration language="en">
<Title><![CDATA[Test]]></Title>
<VfsFolder/>
<AlignNavigation><![CDATA[left]]></AlignNavigation>
<NavigationPosition><![CDATA[b_b]]></NavigationPosition>
<ShowResourceNameAsTitle>false</ShowResourceNameAsTitle>
<Thumbs>
<ShowTitle>false</ShowTitle>
<AlignTitle><![CDATA[left]]></AlignTitle>
<Cols><![CDATA[3]]></Cols>
<Rows><![CDATA[3]]></Rows>
<HighQuality>false</HighQuality>
<Size><![CDATA[150x113]]></Size>
<Filter><![CDATA[none]]></Filter>
<Background>#000000</Background>
</Thumbs>
<Details>
<ShowTitle>false</ShowTitle>
<ShowDescription>false</ShowDescription>
<AlignTitle><![CDATA[left]]></AlignTitle>
<ShowLinkOriginal>false</ShowLinkOriginal>
<Size><![CDATA[600x450]]></Size>
<Filter><![CDATA[none]]></Filter>
<Background>#000000</Background>
</Details>
</PhotoAlbumConfiguration>
</PhotoAlbumConfigurations>
(2) Create a copy from file
/system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum.xsd
as photoalbum_new.xsd.
(3) In folder /sites/default/ you have the xsl file
convert_photoalbum.xsl. That file contains the convert rules. In that
example, that file only makes that the file to convert will be written
again. But, in the new written file the path to the main schema file
goes to the new xsd main file "photoalbum_new.xsd" created in (2) then.
The content from the xsl file is that:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<PhotoAlbumConfigurations
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum_new.xsd">
<xsl:apply-templates/>
</PhotoAlbumConfigurations>
</xsl:template>
<xsl:template match="PhotoAlbumConfigurations">
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="" match="* | @*">
<xsl:copy>
<xsl:apply-templates select="* | @* | text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//PhotoAlbumConfiguration">
<xsl:variable name="lang" select="@language" />
<xsl:element name="PhotoAlbumConfiguration"
use-attribute-sets="PhotoAlbumConfigurationAttributes">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:attribute-set name="PhotoAlbumConfigurationAttributes">
<xsl:attribute name="language"><xsl:value-of
select="@language"/></xsl:attribute>
</xsl:attribute-set>
</xsl:stylesheet>
(4) You go in the root site. In the content tool "Convert XML contents"
you configure the following settings:
- "Resource type": "photoalbum"
- "VFS folder": /sites/default/xmlkonv/
- "Include subfolders": not selected
- "Transformation file (xsl)": /sites/default/convert_photoalbum.xsl
- "Only count files": not selected
Start the convert tool with "Ok" then.
That is the report output then:
Start Thread transforming XML contents.
Start transforming xml contents.
Parameters:
Resource path: /sites/default/xmlkonv/
Inclusive sub folders: false
Xslt file: /sites/default/convert_photoalbum.xsl
Only count files to transform: false
New xsd main file:
opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum_new.xsd
Start searching for files to transform...
Number of files found to transform: 1
Transform (published) file (encoding type):
/sites/default/xmlkonv/photoalbum.html (UTF-8)
Publishing files...
Result:
Number of files found to transform: 1
Number of files already transformed: 0
Number of errors while transforming: 0
Number of locked files (could not become transformed): 0
All files could become transformed successful.
Finished transforming xml contents.
Statistics:duration: 00:00:02
End Thread transforming XML contents.
(5) The converted file photoalbum.html has that content then:
<?xml version="1.0" encoding="UTF-8"?>
<PhotoAlbumConfigurations
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum_new.xsd">
<PhotoAlbumConfiguration language="en">
<Title><![CDATA[Test]]></Title>
<VfsFolder/>
<AlignNavigation><![CDATA[left]]></AlignNavigation>
<NavigationPosition><![CDATA[b_b]]></NavigationPosition>
<ShowResourceNameAsTitle>false</ShowResourceNameAsTitle>
<Thumbs>
<ShowTitle>false</ShowTitle>
<AlignTitle><![CDATA[left]]></AlignTitle>
<Cols><![CDATA[3]]></Cols>
<Rows><![CDATA[3]]></Rows>
<HighQuality>false</HighQuality>
<Size><![CDATA[150x113]]></Size>
<Filter><![CDATA[none]]></Filter>
<Background>#000000</Background>
</Thumbs>
<Details>
<ShowTitle>false</ShowTitle>
<ShowDescription>false</ShowDescription>
<AlignTitle><![CDATA[left]]></AlignTitle>
<ShowLinkOriginal>false</ShowLinkOriginal>
<Size><![CDATA[600x450]]></Size>
<Filter><![CDATA[none]]></Filter>
<Background>#000000</Background>
</Details>
</PhotoAlbumConfiguration>
</PhotoAlbumConfigurations>
The only difference to (1) is that snippet in the third line:
...
xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum_new.xsd">
In (1) that line was that:
...
xsi:noNamespaceSchemaLocation="opencms://system/modules/org.opencms.frontend.photoalbum/schemas/photoalbum.xsd">
The converted file is not published.
The most important thing is, that you create a new main schema file (in
that example photoalbum_new.xsd). That file you have to use in the xsl
file. With that new xsd file is proved in OpenCms if a file was
converted already.
If you want to have the original xsd file name in your converted file,
you have to do the convert twice. In the first convert you have to do
the necessary convert. And in the second convert you can go back to the
original xsd file name like done in the example in that mail.
Kind Regards,
Mario.
Am 21.06.2011 11:38, schrieb Kunicke, Holger:
> Hello All,
>
> does someone has information or docs about transforming xmlcontent resources
> with the content tool "Convert XML contents".
> I need more information than the output "Error while transformation." :-(
>
> Which XSL transformation method can I use to simulate the content transformation
> (at local client) ?
> Are there other constraints?
>
> Greetings
> Holger
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
--
-------------------
Mario Jäger
Alkacon Software GmbH - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org
More information about the opencms-dev
mailing list