tags:

views:

699

answers:

3

I am trying to create an embedded file containing both XML and XSL. The test is based on "XML and XSL in one file" on dpawson.co.uk. The source looks like this:

<?xml-stylesheet type="text/xml" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
  id    ID #REQUIRED>
]>
<doc>
<xsl:stylesheet id="stylesheet"
                version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  <!-- any xsl:import elements -->
  <xsl:template match="xsl:stylesheet" />
  <!-- rest of your stylesheet -->
</xsl:stylesheet>

<!-- rest of your XML document -->
</doc>

Originally I have made a working XML and XSL file. The XML looks like this:

<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<Report>
    <ReportFor>Test Data</ReportFor>
    <CreationTime>2009-07-29 05:37:14</CreationTime>
</Report>

And the data.xsl file looks like this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  <xsl:template match="/">
    <!-- ... -->
    <xsl:value-of select="Report/ReportFor" />
    <!-- ... -->
    <xsl:value-of select="Report/CreationTime"/>
    <!-- ... -->
  </xsl:template>
</xsl:stylesheet>

Based on these I'm trying to create an embedded XML file containing both XML and XSL.

Currently this file looks like this:

<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
  id    ID #REQUIRED>
]>
<doc>
<xsl:stylesheet id="stylesheet"
                version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  <!-- any xsl:import elements -->
  <xsl:template match="xsl:stylesheet" />
  <!-- rest of your stylesheet -->
  <xsl:template match="/">
    <!-- ... -->
    <xsl:value-of select="Report/ReportFor" />
    <!-- ... -->
    <xsl:value-of select="Report/CreationTime"/>
    <!-- ... -->
  </xsl:template>
</xsl:stylesheet>

<!-- rest of your XML document -->
<Report>
    <ReportFor>Test Data</ReportFor>
    <CreationTime>2009-07-29 05:37:14</CreationTime>
</Report>

</doc>

The problem with this document is that the <xsl:value-of> does not retrieve the data represented in the XML section. How is it possible for <xsl:value-of> to recognize the embedded data? Is some special syntax needed?

A: 

Does this need to use the "." operator to get the value?

 <xsl:value-of select="Report/ReportFor/."/>
shambleh
+1  A: 

See http://stackoverflow.com/questions/360628/embed-xsl-into-an-xml-file

Scoregraphic
I was about to post the "embed the XML in the XSL" suggestion, but since that has already been answered: A link is better.
Tomalak
A: 

You are missing the doc element in your template match attribute. Try this instead:

<xsl:template match="/doc">
   <xsl:value-of select="Report/ReportFor" />
</xsl:template>
Jörn Horstmann