[opencms-dev] Information about content tool "Convert XML content" ?

Mario Jäger m.jaeger at alkacon.com
Mon Jun 27 11:03:09 CEST 2011


Hi Hein,

You still can use xml pages in OpenCms 8. But, the new OpenCms 8 
features like ADE are made for xml contents. That is why, if you want to 
use these new features, you have to convert your xml pages to xml 
contents or create xml contents. But, you do not need to do that at 
once. Because, you also can use xml pages (of course without the new 
features) if you use the new features with xml contents. But, you have 
to use different templates for the xml pages and the xml contents (using 
the new features).

Is it possible to convert xml pages to any xml content. I have created a 
little example to show that. There is converted a xml page to the 
resource type "alkacon-newsletter" (resource type in the OAMP module 
com.alkacon.opencms.newsletter).

(1) You have a folder /sites/default/xmlpageconv/ with a xml page 
"xmlpage.html" with that content:

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

<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="http://www.opencms.org/dtd/6.0/xmlpage.xsd">
   <page language="de">
     <element name="text1">
       <links/>
       <content><![CDATA[test de]]></content>
     </element>
   </page>
   <page language="en">
     <element name="text1">
       <links/>
       <content><![CDATA[test en]]></content>
     </element>
   </page>
</pages>

(2) Create the xsl with with the convert rules as 
/sites/default/convert_xmlpage.xsl with that content:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:template match="/">	
		<AlkaconNewsletterMails 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="opencms://system/modules/com.alkacon.opencms.newsletter/schemas/newsletter_mail.xsd">
			<xsl:apply-templates/>
		</AlkaconNewsletterMails>
	</xsl:template>

	<xsl:template match="pages">
         	<xsl:apply-templates/>
     	</xsl:template>

	<xsl:template name="" match="* | @*">	
		<xsl:copy>
			<xsl:apply-templates select="* |  @* | text()"/>
		</xsl:copy>
	</xsl:template>
	
	<xsl:template match="//page">
	    <xsl:variable name="lang" select="@language" />
	
             <xsl:element name="AlkaconNewsletterMail" 
use-attribute-sets="pageAttributes">
             	<From><![CDATA[noreply at localhost]]></From>
     		<Subject><![CDATA[Newsletter]]></Subject>
             	<xsl:apply-templates/>
             	<Config>
       			<Html>true</Html>
       			<MailHead><![CDATA[<html>
<head>
<title>%(title)</title>
<style type="text/css">
<!--
body { font-family: Verdana, Arial, Helvetica, sans-serif;  font-size: 
12px; color: #000000; }
h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 
16px; font-weight: bold; color: #0000CC;  }
table { border-collapse: collapse; border: 1px solid #333333; }
a { color:#CC3333; text-decoration:none; }
//-->
</style>
<base href="%(siteurl)" />
</head>
<body>]]></MailHead>
       <MailFoot><![CDATA[</body>
</html>]]></MailFoot>
     </Config>
             </xsl:element>
    	</xsl:template>
    	
    	<xsl:template match="///element">
		<Text name="Text0">
      			<links>
      				<xsl:value-of select="links"/>
      			</links>
       			<content>
				<xsl:value-of select="content"/>
			</content>		
		</Text>
	</xsl:template>
  	
  	<xsl:attribute-set name="pageAttributes">
		<xsl:attribute name="language"><xsl:value-of 
select="@language"/></xsl:attribute>
	</xsl:attribute-set>
  	
</xsl:stylesheet>


That xsl file includes the rules, that the converted xml page is a 
newsletter with the default settings then. But, the mail text includes 
the content from the original xml page.

(3) You select in the content menu from the file to convert 
/sites/default/xmlpageconv/xmlpage.html "Advanced" -> "Change type" and 
select "Alkacon newsletter" and "Ok". Then, you have changed the 
resource type from that file from "xmlpage" to "alkacon-newsletter".

(4) Go in the root site and go in the content tool "Convert xml 
contents" then.

Configure the following settings there:

Resource type: alkacon-newsletter

VFS folder: /sites/default/xmlpageconv/

Include subfolders: Not selected

Transformation file (xsl): /sites/default/convert_xmlpage.xsl

Only count files: Not selected

Use the "Ok" button then. Then that report is written:

Start Thread transforming XML contents.
Start transforming xml contents.
Parameters:
Resource path: /sites/default/xmlpageconv/
Inclusive sub folders: false
Xslt file: /sites/default/convert_xmlpage.xsl
Only count files to transform: false
New xsd main file: 
opencms://system/modules/com.alkacon.opencms.newsletter/schemas/newsletter_mail.xsd
Start searching for files to transform...
Number of files found to transform: 1
Transform (published) file (encoding type): 
/sites/default/xmlpageconv/xmlpage.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:00
End Thread transforming XML contents.


(5) The converted file /sites/default/xmlpageconv/xmlpage.html has that 
content then:

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

<AlkaconNewsletterMails 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="opencms://system/modules/com.alkacon.opencms.newsletter/schemas/newsletter_mail.xsd">
   <AlkaconNewsletterMail language="de">
     <From><![CDATA[noreply at localhost]]></From>
     <Subject><![CDATA[Newsletter]]></Subject>
     <Text name="Text0">
       <links/>
       <content><![CDATA[test de]]></content>
     </Text>
     <Config>
       <Html>true</Html>
       <MailHead><![CDATA[<html>
<head>
<title>%(title)</title>
<style type="text/css">
<!--
body { font-family: Verdana, Arial, Helvetica, sans-serif;  font-size: 
12px; color: #000000; }
h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 
16px; font-weight: bold; color: #0000CC;  }
table { border-collapse: collapse; border: 1px solid #333333; }
a { color:#CC3333; text-decoration:none; }
//-->
</style>
<base href="%(siteurl)" />
</head>
<body>]]></MailHead>
       <MailFoot><![CDATA[</body>
</html>]]></MailFoot>
     </Config>
   </AlkaconNewsletterMail>
   <AlkaconNewsletterMail language="en">
     <From><![CDATA[noreply at localhost]]></From>
     <Subject><![CDATA[Newsletter]]></Subject>
     <Text name="Text0">
       <links/>
       <content><![CDATA[test en]]></content>
     </Text>
     <Config>
       <Html>true</Html>
       <MailHead><![CDATA[<html>
<head>
<title>%(title)</title>
<style type="text/css">
<!--
body { font-family: Verdana, Arial, Helvetica, sans-serif;  font-size: 
12px; color: #000000; }
h1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 
16px; font-weight: bold; color: #0000CC;  }
table { border-collapse: collapse; border: 1px solid #333333; }
a { color:#CC3333; text-decoration:none; }
//-->
</style>
<base href="%(siteurl)" />
</head>
<body>]]></MailHead>
       <MailFoot><![CDATA[</body>
</html>]]></MailFoot>
     </Config>
   </AlkaconNewsletterMail>
</AlkaconNewsletterMails>

(6) To set the "template-elements" property to the right value you also 
have to use the content tool "Change Property Values" then.



Because, changing the resource type from "xmlpage" to 
"alkacon-newsletter" only works directly on the file, you can not do 
step 3 for all xml pages at once. If you do not want to do step 3 for 
each file separate, you could something implement to change the resource 
type from "xmlpage" to the other xml content resource type for all xml 
pages at once.

Kind Regards,
Mario.



Am 22.06.2011 21:15, schrieb Hein van der Kallen:
> Mario,
> You gave a  very helpful explanation.
>
> additional question :
> Is it possible to use the same "Convert XML content"  to convert xml-pages
> to xml-content ?
> Is there also an example of such a conversion ?
>
> We use xml-pages heavily since opencms 5.0.
> But it seems to become a forgotten corner in opencms.
>
> opencms 8 seems to be no improvement for mainly xml-page sites.
>
> Would a conversion to xml-content be useful ? why ?
> or even necessary ?
>
> Greetings
> Hein van der Kallen
>
> ----- Original Message -----
> From: "Mario Jäger"<m.jaeger at alkacon.com>
> To:<opencms-dev at opencms.org>
> Sent: Wednesday, June 22, 2011 10:33 AM
> Subject: Re: [opencms-dev] Information about content tool "Convert XML
> contents" ?
>
>
>> 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
>>
>> _______________________________________________
>> 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
>>
>
>
> _______________________________________________
> 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