Tôi đang cố tạo một tệp nhúng chứa cả XML và XSL. Bài kiểm tra dựa trên số "XML and XSL in one file" trên dpawson.co.uk. Nguồn trông giống như sau:Cách làm việc với tệp XML và XSL được nhúng
<?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>
Ban đầu tôi đã tạo một tệp XML và XSL hoạt động. XML trông như thế này:
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<Report>
<ReportFor>Test Data</ReportFor>
<CreationTime>2009-07-29 05:37:14</CreationTime>
</Report>
Và file data.xsl
trông như thế này:
<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>
Dựa trên những Tôi đang cố gắng để tạo ra một tập tin XML nhúng chứa cả XML và XSL.
Hiện nay tập tin này trông như thế này:
<?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>
Vấn đề với tài liệu này là <xsl:value-of>
không lấy dữ liệu trình bày trong phần XML. Làm cách nào để có thể cho <xsl:value-of>
nhận ra dữ liệu được nhúng? Có cần một cú pháp đặc biệt nào không?
Xem [http://stackoverflow.com/questions/360628/embed-xsl-into-an-xml-file](http://stackoverflow.com/questions/360628/embed -xsl-into-an-xml-file) – Scoregraphic
Tôi sắp đăng đề xuất "nhúng XML vào XSL", nhưng vì nó đã được trả lời: Một liên kết tốt hơn. – Tomalak