Re: [xsl] Transforming XML copied via XSLT

Subject: Re: [xsl] Transforming XML copied via XSLT
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Wed, 27 Jan 2010 22:31:42 +0100
Dear Rob,

Although your answer doesn't help us understand your question any better, I'll try to guess what might be the issue.

If you want to transform something, you probably want to try xsl:apply-templates instead of xsl:copy-of?

This mailing list cannot substitute training and self-study. There's an XSLT tutorial and reference at zvon.org, to start with (still useful, although it covers only XSLT 1.0): http://www.zvon.org/xxl/XSLTutorial/Output/index.html

And there's of course the excellent red book by His Mikeness: http://www.wrox.com/WileyCDA/WroxTitle/productCd-0470192747.html

When I started using XSLT two years ago (consciously skipping XSLT 1.0 all the time before), I found the following book useful: http://oreilly.com/catalog/9780596009748

Back to your problem. If this is the file to be included:

---test.html--------
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<title>include this</title>
</head>
<body>
<p>included</p>
</body>
</html>
---/test.html-------


and this is the xslt:

---test.xsl---------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:html="http://www.w3.org/1999/xhtml";
  version="2.0"
  exclude-result-prefixes="html">

<xsl:output method="xml" indent="yes" />

  <xsl:template name="main">
    <outer>
      <xsl:apply-templates select="document('test.html')" />
    </outer>
  </xsl:template>

  <xsl:template match="html:html">
    <xsl:apply-templates select="html:body/*" />
  </xsl:template>

  <xsl:template match="html:p">
    <inner>
      <xsl:apply-templates />
    </inner>
  </xsl:template>

</xsl:stylesheet>
---/test.xsl---------

you will get this result
--------------
<?xml version="1.0" encoding="UTF-8"?>
<outer>
   <inner>included</inner>
</outer>
--------------

by invoking

PROMPT> saxon -it:main -xsl:test.xsl

(where saxon is the name of the script that invokes your XSLT processor). The example above should also work as XSLT 1.0.

You see that what used to be <p> in the XHTML file now becomes <inner> by virtue of a transformation. That's what xsl:apply-templates or xsl:call-template are for. xsl:copy-of is just for (identical) copying, as the name suggests.

Hope this helps.

Gerrit


On 27.01.2010 21:59, Rob Belics wrote:
On Wed, 2010-01-27 at 14:21 -0500, List Owner wrote:
It would be far easier to answer your question if you supplied examples of:

    1. your source XML
    2. the target of the transform (in this case, the HTML you want)
    3. the code you have, so we can see why you aren't getting the
       results you want.

You seem to have supplied source XML, but we don't know from your
message exactly what you want to transform it into.

I suggest re-posting your question with some additional information.

-- Tommie

...
Essentially, I have this:
<menu>
	<sandwiches>
		<html:h1>Sandwiches</html:h1>
		<xsl:copy-of style="document('http://mysite.com/food')">
	</sandwiches>
</menu>

Please bear with my experimenting.
The copied XML data needs to be transformed into links and form<input>
but I don't know if that can be done here. Can someone point me in the
right direction, tips, hints and all that?
...
This is a different question needing different answers. You must think
my last thread applies here but it does not.

Current Thread