Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XSL for recursive transformation (http://www.velocityreviews.com/forums/t170556-xsl-for-recursive-transformation.html)

Indy 02-15-2006 01:03 PM

XSL for recursive transformation
 
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


Joe Kesselman 02-15-2006 01:10 PM

Re: XSL for recursive transformation
 
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

Nick Kew 02-15-2006 02:25 PM

Re: XSL for recursive transformation
 
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

Peter Flynn 02-15-2006 10:27 PM

Re: XSL for recursive transformation
 
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/

Joe Kesselman 02-16-2006 01:22 AM

Re: XSL for recursive transformation
 
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

Indy 02-16-2006 11:34 AM

Re: XSL for recursive transformation
 
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


Richard Tobin 02-16-2006 12:20 PM

Re: XSL for recursive transformation
 
In article <1140089654.133522.14350@o13g2000cwo.googlegroups. com>,
Indy <indeera@gmail.com> 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



Joe Kesselman 02-16-2006 01:24 PM

Re: XSL for recursive transformation
 
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

Joe Kesselman 02-16-2006 01:25 PM

Re: XSL for recursive transformation
 
.... 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

Andy Dingley 02-16-2006 04:32 PM

Re: XSL for recursive transformation
 
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.



All times are GMT. The time now is 11:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57