2009-07-29 12 views
6

Próbuję utworzyć osadzony plik zawierający zarówno XML, jak i XSL. Test jest oparty na "XML and XSL in one file" na dpawson.co.uk. Źródło wygląda tak:Praca z osadzonym plikiem XML i XSL

<?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"> 
    <!-- any xsl:import elements --> 
    <xsl:template match="xsl:stylesheet" /> 
    <!-- rest of your stylesheet --> 
</xsl:stylesheet> 

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

Pierwotnie zrobiłem działający plik XML i XSL. XML wygląda następująco:

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

a plik data.xsl wygląda następująco:

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

W oparciu o te Próbuję utworzyć osadzony plik XML zawierający zarówno XML i XSL.

Obecnie plik ten wygląda następująco:

<?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"> 
    <!-- 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> 

Problem z tego dokumentu jest to, że <xsl:value-of> nie odzyskać dane przedstawione w sekcji XML. Jak to możliwe, aby <xsl:value-of> rozpoznawać osadzone dane? Czy potrzebna jest specjalna składnia?

+0

patrz [http://stackoverflow.com/questions/360628/embed-xsl-into-an-xml-file](http://stackoverflow.com/questions/360628/embed -xsl-into-an-xml-file) – Scoregraphic

+1

Zamierzałem opublikować sugestię "osadzam XML w XSL", ale ponieważ została już odebrana: link jest lepszy. – Tomalak

Odpowiedz

0

Czy trzeba użyć "." operator, aby uzyskać wartość?

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

Brakuje elementu doc ​​w atrybucie dopasowania szablonu. Spróbuj to zamiast:

<xsl:template match="/doc"> 
    <xsl:value-of select="Report/ReportFor" /> 
</xsl:template> 
Powiązane problemy