2009-07-29 11 views
6

Sto provando a creare un file incorporato contenente sia XML che XSL. Il test si basa su "XML and XSL in one file" su dpawson.co.uk. La fonte è simile al seguente:Come lavorare con un file XML e XSL incorporato

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

Originariamente ho creato un file XML e XSL funzionante. L'XML è simile al seguente:

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

e il file data.xsl assomiglia a questo:

<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> 

Sulla base di questi Sto cercando di creare un file XML incorporato contenente sia XML e XSL.

Attualmente questo file si presenta così:

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

Il problema di questo documento è che il <xsl:value-of> non recupera i dati rappresentati nella sezione XML. Come è possibile che <xsl:value-of> riconosca i dati incorporati? È necessaria una sintassi speciale?

+0

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

+1

Stavo per postare il suggerimento "incorporare l'XML nel XSL", ma dal momento che è già stato risposto: Un link è migliore. – Tomalak

risposta

0

È necessario utilizzare "." operatore per ottenere il valore?

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

Manca l'elemento doc nell'attributo di corrispondenza del modello. Prova a modificare:

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