[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Converting SSI variables to XML

Subject: Re: Converting SSI variables to XML
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 11 Sep 2006 17:49:44 +0200
ssi set var
Hi Tom,

Looking at your data, I'd recommend one of two approaches:

1. Make the conversion a two step process. You CDATA section closely resembles something that looks like XML to me, turning it into XML will give you a document that you can process more easily in the second step. This seems to be the approach you took.

2. Using the regular expression approach, you can turn the CDATA section into a node-set and traverse over the contents of this node-set using normal XSLT. This is a one-pass approach (meaning: it will need only one xslt processing call) and I normally use it that way.

On your problem with getting the number out. It appears as if it always has something *without* a dot at the end and the number itself will consist of only numbers. The easiest (?) way to extract the number is using replace() function:

<xsl:value-of select="replace ( @name , '^.*\.([0-9]+)\.[^.]+$', '$1' ) " />

In human language this says:
^.+      from the start of the string, one or more chars
\.       then a dot
([0-9]+) grab one or more digits and place it in $1
\.       followed by a dot
[^.]+    followed by one ore more non-dots
$        till the end of the string

'$1' replaces the whole string between the anchors ^ and $ with the number.

Hope this helps,

Cheers,
Abel Braaksma
http://abelleba.metacarpus.com




tom tom wrote:
Hi all, I wish to turn the following CDATA input:

<xml>

<![CDATA[

<!--#set var="t.news.1.title" value="This is the title"-->
<!--#set var="t.news.1.image_small" value="smallimage"-->
<!--#set var="t.news.1.image_large" value="largeimage"-->

<!--#set var="t.news.2.title" value=""-->
<!--#set var="t.news.2.image_small" value=""-->
<!--#set var="t.news.2.image_large" value=""-->

<!--#set var="t.news.3.title" value=""-->
<!--#set var="t.news.3.image_small" value=""-->
<!--#set var="t.news.3.image_large" value=""-->


]]> </xml>


Into XML as follows using XSLT 2:


<ts>
 <group num="1">
  <var name="t.news.1.title" value="This is the title"/>
  <var name="t.news.1.image_small" value="smallimage"/>
  <var name="t.news.1.image_large" value="largeimage"/>
 </group>
 <group num="2">
  etc.....
 </group>
</ts>

I have used the analyze-string function to do a regex match on the HTML comments, it then extracts the values of 'var' and 'value' to create:

<ts>

  <var name="t.news.1.title" value="This is the title"/>
  <var name="t.news.1.image_small" value="smallimage"/>
  <var name="t.news.1.image_large" value="largeimage"/>


etc.....


</ts>

To add the grouping I will need to do another pass over this data however I am finding it complex to extract the numerical data from the string at @name and it seems unnecessary complex. I have also tried nesting xsl:analyze-string elements to create a group first then the individual variables. Can anyone recommend the correct way to do this?

Thanks in advance

Tom

_________________________________________________________________
Download the new Windows Live Toolbar, including Desktop search! http://toolbar.live.com/?mkt=en-gb

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.