Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL for recursive transformation

Reply
Thread Tools

XSL for recursive transformation

 
 
Indy
Guest
Posts: n/a
 
      02-15-2006
Hi,
I have a XHTML input file with custom tag which specifies html
fragments to include
For example:
<html>
....
<include frag1="frag1.html" frag2="frag2.html">
More html here
</include>
....html...
<include frag1="frag3.html" ....>...

</html>
The include tag can be nested. The contents of an include tag would be
combined with the fragments [frag1.html and frag2.html] to produce the
output xml which would replace the currently processed include tag.
After that the whole output has to be checked for valid XML. And the
process is continued until there are no more include tags.

I was wondering about the best way to go about doing this. Is XSL
suitable? If so how?

Thanks
Indy

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      02-15-2006
Indy wrote:
> I was wondering about the best way to go about doing this. Is XSL
> suitable? If so how?


Given that XHTML is an XML language, the *right* way to do this would be
to use XInclude tags. Assuming your XHTML processor supports XInclude,
of course.

If it doesn't -- yes, you can implement XInclude, or similar
functionality, in XSLT if you want to. One such implementation can be
seen at http://www.dpawson.co.uk/xsl/sect2/include.html

(It's always worth checking Dave Pawson's XSLT FAQ website. He's done a
very good job of collecting many of the best answers from the XSLT
user's mailing list. Which, by the way, is also worth subscribing to if
you're looking for a deeper understanding of stylesheets.)


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
 
 
 
Nick Kew
Guest
Posts: n/a
 
      02-15-2006
Joe Kesselman wrote:
> Indy wrote:
>
>> I was wondering about the best way to go about doing this. Is XSL
>> suitable? If so how?

>
>
> Given that XHTML is an XML language, the *right* way to do this would be
> to use XInclude tags. Assuming your XHTML processor supports XInclude,
> of course.


FWIW, mod_transform for Apache is an XSLT filter that supports XInclude
(based on libxml2/libxslt). So it's a solved problem on the Web.

However, XSLT is not a good solution to this, except for small
documents. Inclusion can be streamed, so it'll be hugely faster
and more scalable using a SAX-based parser. mod_publisher would
be a better choice.

--
Nick Kew
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      02-15-2006
Indy wrote:
> Hi,
> I have a XHTML input file with custom tag which specifies html
> fragments to include
> For example:
> <html>
> ...
> <include frag1="frag1.html" frag2="frag2.html">
> More html here
> </include>
> ...html...
> <include frag1="frag3.html" ....>...
>
> </html>
> The include tag can be nested. The contents of an include tag would be
> combined with the fragments [frag1.html and frag2.html] to produce the
> output xml which would replace the currently processed include tag.
> After that the whole output has to be checked for valid XML. And the
> process is continued until there are no more include tags.
>
> I was wondering about the best way to go about doing this.


Why not just use entity declarations?

///Peter
--
XML FAQ: http://xml.silmaril.ie/
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      02-16-2006
Peter Flynn wrote:
> Why not just use entity declarations?


Parsed entities are pretty much dying as XML Schema replaces DTDs.
Schemas don't have any equivalent. XInclude/XLink were supposed to take
over that role.


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Indy
Guest
Posts: n/a
 
      02-16-2006
Hi,
Thanks for your comments, I tried using XInclude tags but came across
some problems.
The fragments that I'm trying to include are not valid XML themselves,
they could be for example be:
---sof---
<table><tr><td>This is a header</td></tr>
---eof---

and only when the fragments are assembled it forms a valid XML.

Do you think XInclude can still be used to achieve this?

Thanks again,
Indeera

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      02-16-2006
In article <(E-Mail Removed). com>,
Indy <(E-Mail Removed)> wrote:
>The fragments that I'm trying to include are not valid XML themselves,

....
>and only when the fragments are assembled it forms a valid XML.


>Do you think XInclude can still be used to achieve this?


No. XInclude operates at the level of the XML Infoset, not on
characters. You will need to use a non-XML tool to put them together.

-- Richard


 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      02-16-2006
Indy wrote:
> The fragments that I'm trying to include are not valid XML themselves,


In which case XML-aware tools aren't going to handle them. Write
something text-based.



--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      02-16-2006
.... or redesign the whole problem so you're working with XML structure
rather than text fragments.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      02-16-2006
Indy wrote:

> I have a XHTML input file with custom tag which specifies html
> fragments to include


Other posters have suggested ways to include XML fragments in XML.

However I'd advise against this, because you're trying to embed HTML as
the fragment and HTML is _not_ XML. HTML needs to be processed with
text or SGML aware tools, not XML. What happens if you encounter a HTML
fragment that's not well-formed? What happens if you _want_ to use a
fragment that's not well forned?

RSS has addressed this same problem before now. Worth reading the
background.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use output of XSL transformation as new XSL stylesheet barney.b@iname.com XML 0 01-16-2006 02:29 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
Nested DataSet / Xsl Transformation George Durzi ASP .Net 0 03-24-2005 06:44 PM
XSL Transformation - Dynamic Generation of XML Content Hugo Ferreira ASP .Net 0 07-14-2004 11:25 AM
Timeout on Xsl Transformation George Durzi ASP .Net 0 12-29-2003 07:46 PM



Advertisments