我是XSLT新手。我正在尝试开发XSLT,按照下面的代码将XML数据转换为HTML。
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:key name="Name" match="Item" use="@Name"/>
<xsl:template match="item">
<html>
<body>
<h1>Course Profile</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Item">
<xsl:if test="string-length(@Name) > 0 ">
<span>Name: </span>
<xsl:value-of select="@Name"/>
 
</xsl:if>
<xsl:if test="string-length(@Title) > 0 ">
<span>Title: </span>
<xsl:value-of select="@Title"/>
 
</xsl:if>
<xsl:if test="string-length(@Description) > 0 and @Description!=@Title">
<span>Description: </span>
<xsl:value-of select="@Description"/>
 
</xsl:if>
<xsl:if test="string-length(@Value) > 0 ">
<span>Value: </span>
<xsl:value-of select="@Value"/>
 
</xsl:if>
<xsl:if test="string-length(Name) > 0 ">
<span>Actual value: </span>
<xsl:value-of select="Name"/>
 
</xsl:if>
<br/>
<hr/>
</xsl:template>
</xsl:stylesheet>
XHTML中的数据(不是外观!-我不想使用XSL-FO)来自这样的XML数据(这是我的问题-它并不总是相同的xsd):
<?xml version="1.0" encoding="UTF-8"?>
<StructureData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Object ID="cacms^977" StructureLevel="5" Title="test programme">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="author" Value="rien"/>
<Item Name="last_updated_time" Value="2012-05-28-07.02.09"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="title" Value="test programme"/>
<Item Name="description" Value="revalidation"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata>
<Item Index="1" Name="Programme Type" Value="Appip"/>
<Item Index="2" Name="Course Type" Value="Adult learning >20"/>
<Item Index="2" Name="Course Code" Value="xxTT2"/>
<Item Index="1" Name="Status" Value="01-In development"/>
<Item Index="1" Name="Metadata Schema" Value="LOM 1.0"/>
<Item Index="1" Name="Minimum Version" Value="IE 7.0"/>
<Item Index="1" Name="Maximum Version" Value="IE 8.0"/>
<Item Index="17" Name="Awarding Body" Value="TT"/>
<Item Index="1" Name="NQ Award Type" Value="Major Award"/>
<Item Index="6" Name="NQ Award Level" Value="Level 06"/>
<Item Index="6" Name="Award Title" Value="none"/>
</CustomMetadata>
</Object>
<Object ID="cacms^978" StructureLevel="4" Title="test phase">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="author" Value="rien"/>
<Item Name="last_updated_time" Value="2012-05-28-07.02.10"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="title" Value="test phase"/>
<Item Name="description" Value="revalidation"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata/>
</Object>
<Object ID="cacms^979" StructureLevel="3" Title="test module">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="author" Value="rien"/>
<Item Name="last_updated_time" Value="2012-05-28-07.02.10"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="title" Value="test module"/>
<Item Name="description" Value="revalidation"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata>
<Item Index="1" Name="NQ Award Type" Value="Major Award"/>
<Item Index="6" Name="NQ Award Level" Value="Level 06"/>
<Item Index="6" Name="Expiry/Review Date" Value="2012-05-09"/>
<Item Index="10" Name="Typical Learning Time (Duration hours)" Value=""/>
<Item Index="10" Name="Award Title" Value="non"/>
<Item Index="17" Name="Awarding Body" Value="T"/>
</CustomMetadata>
</Object>
<Object ID="cacms^980" StructureLevel="2" Title="test unit">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="author" Value="rien"/>
<Item Name="last_updated_time" Value="2012-08-22-10.21.17"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="title" Value="May 9 test unit - Sunny"/>
<Item Name=" description" Value="revalidation"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata/>
</Object>
<Object ID="cacms^1001" StructureLevel="1" Title="test cluster ">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="author" Value="rien"/>
<Item Name="last_updated_time" Value="2012-08-22-10.15.37"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="title" Value="test cluster"/>
<Item Name="description" Value="delete"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata>
<Item Name="Phase" Value="NCDB"/>
</CustomMetadata>
</Object>
<Object ID="cacms^1053" StructureLevel="0" Title="test ">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="sound" Value=""/>
<Item Name="author" Value="rien"/>
<Item Name="last_updated_time" Value="2012-05-28-07.02.11"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata/>
</Object>
<Object ID="cacms^1054" StructureLevel="0" Title="reverificaton use of templated - Sunny">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="sound" Value=""/>
<Item Name="author" Value="rien"/>
<Item Name="last_updated_time" Value="2012-05-28-07.02.11"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata/>
<ObjectData>
<Item Description="Advanced Table Title Bar Cover Page" ID="cacms^2879" Title="reverification Template Cover page QA 39/01 Training Plan Title Bar" Type="Advanced Table">
<row>
<col><![CDATA[<p> </p><p>CACMS Re-verificiation text <em>Version X.Y Month Year italics</em></p><p> </p>]]></col>
</row>
</Item>
</ObjectData>
</Object>
<Object ID="cacms^1055" StructureLevel="0" Title="May 14 test page 1 doc mode">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="sound" Value=""/>
<Item Name="author" Value=""/>
<Item Name="last_updated_time" Value="2012-05-28-07.02.11"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata/>
<ObjectData>
<Item Description="Advanced Table Title Bar Cover Page" ID="cacms^2866" Title="May 9 test page 1 non doc mode_1 - Title Bar" Type="Advanced Table">
<row>
<col><![CDATA[<p> </p><p>Domestic Appliance Servicing <em>Version 4.6 September 2011</em></p><p> </p>]]></col>
</row>
</Item>
<Item Description="QA39/01 Training Plan Title Block" ID="cacms^2867" Title="QA39/01 Training Plan Title Block" Type="Advanced Table">
<row>
<col><![CDATA[<p><em></em> </p>]]></col>
</row>
<row>
<col>TT - TT</col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col><![CDATA[<p><em>TRAINING PLAN</em></p>]]></col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col><![CDATA[<p><em>DESIGNED TO STANDARD NO. QA39/01</em></p>]]></col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
</Item>
<Item Description="Domestic Appliance Servicing QA39/01" ID="cacms^2869" Title="May 9 test page 1 non doc mode_35 - Domestic Appliance Servicing MANCO QA39/01" Type="Advanced Table">
<row>
<col><![CDATA[<strong>GLM CODE</strong>]]></col>
<col><![CDATA[<strong>MANCO CODES</strong> ]]></col>
<col/>
<col/>
</row>
<row>
<col><![CDATA[<strong>XX028</strong>]]></col>
<col><![CDATA[<strong>76170</strong>]]></col>
<col><![CDATA[ ]]></col>
<col><![CDATA[ ]]></col>
</row>
</Item>
<Item Description="Advanced Table QA39 Status Block" ID="cacms^2870" Title="May 9 test page 1 non doc mode_73 - QA39 Status Block" Type="Advanced Table">
<row>
<col>STATUS</col>
<col/>
<col/>
<col/>
</row>
<row>
<col>PROPOSAL DATE</col>
<col>TT INTERNAL APPROVAL DATE</col>
<col>AWARD COUNCIL VALIDATION DATE</col>
<col>REVIEW BY DATE</col>
</row>
<row>
<col>AUGUST 1995</col>
<col>JUNE 2010</col>
<col><![CDATA[ ]]></col>
<col>JUNE 2005</col>
</row>
</Item>
<Item Description="TT logo with no Tagline at 300 dpi" ID="cacms^TT99" Title="TT Logo no Tagline 300 dpi" Type="Graphic"/>
<Item Description="Text" ID="cacms^2871" Title="test page 1 non doc mode_107 - Funded statement" Type="Text"> Funded financed </Item>
<Item Description="Programme Title Block QA39/01" ID="cacms^2874" Title="May 14 test page 1 doc mode_14 - Programme Title Block" Type="Advanced Table">
<row>
<col><![CDATA[<strong><em>TRAINING TITLE</em></strong>]]></col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col><![CDATA[<p><strong> Domestic Appliance Servicing</strong></p>]]></col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col><![CDATA[<em>   Version 4.6 September 2011</em>]]></col>
</row>
</Item>
</ObjectData>
</Object>
<Object ID="cacms^981" StructureLevel="1" Title="test cluster">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="author" Value="rien"/>
<Item Name="last_updated_time" Value="2012-05-28-07.02.10"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="title" Value="test cluster"/>
<Item Name="description" Value="test"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata>
<Item Name="Phase" Value="re-verification"/>
</CustomMetadata>
</Object>
<Object ID="cacms^1047" StructureLevel="0" Title="QA39 Test Type codes template - Sunny">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="Adult Training Templates"/>
<Item Name="sound" Value=""/>
<Item Name="author" Value=""/>
<Item Name="last_updated_time" Value="2012-05-28-07.02.11"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata/>
<ObjectData>
<Item Description="Key to Test Type Codes" ID="cacms^2881" Title="Training Plan - table of codes" Type="Advanced Table">
<row isHeader="true">
<col><![CDATA[<p> </p><p>TRAINING PLAN</p><p> </p>]]></col>
<col/>
</row>
<row>
<col>KEY TO TEST TYPE CODES </col>
<col/>
</row>
<row>
<col>Assignment</col>
<col><![CDATA[<p>A</p>]]></col>
</row>
<row>
<col>Course Work</col>
<col>CW</col>
</row>
<row>
<col>Drawing</col>
<col>D</col>
</row>
<row>
<col>Essay (Written)</col>
<col>E</col>
</row>
<row>
<col>Integrated Assessment</col>
<col>IA</col>
</row>
<row>
<col>Multiple Choice</col>
<col>MC</col>
</row>
<row>
<col>Not Applicable</col>
<col>NA</col>
</row>
<row>
<col>Oral</col>
<col>O</col>
</row>
<row>
<col>Practical</col>
<col>P</col>
</row>
<row>
<col>Profiling</col>
<col>PF</col>
</row>
<row>
<col>Project</col>
<col>PR</col>
</row>
<row>
<col>Short Answer</col>
<col>SA</col>
</row>
<row>
<col>Workplace Observation</col>
<col>WO</col>
</row>
<row>
<col>Written</col>
<col>W</col>
</row>
</Item>
</ObjectData>
</Object>
<Object ID="cacms^1048" StructureLevel="0" Title=" non-doc mode page">
<CoreMetadata>
<Item Name="version" Value="1"/>
<Item Name="language" Value="English"/>
<Item Name="subject" Value="UAT testing content"/>
<Item Name="sound" Value=""/>
<Item Name="author" Value=""/>
<Item Name="last_updated_time" Value="2012-05-28-07.39.04"/>
<Item Name="last_updated_by" Value="rien"/>
<Item Name="expiry_date" Value=""/>
</CoreMetadata>
<CustomMetadata/>
<ObjectData>
<Item Description="QA39/01 Training Plan Title Block" ID="cacms^2867" Title="QA39/01 Training Plan Title Block" Type="Advanced Table">
<row>
<col><![CDATA[<p><em></em> </p>]]></col>
</row>
<row>
<col>TT - TT</col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col><![CDATA[<p><em>TRAINING PLAN</em></p>]]></col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col><![CDATA[<p><em>DESIGNED TO STANDARD NO. QA39/01</em></p>]]></col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
</Item>
<Item Description="Programme Title Block QA39/01" ID="cacms^2868" Title="test page 1 non doc mode_14 - Programme Title Block" Type="Advanced Table">
<row>
<col><![CDATA[<p> </p>]]></col>
</row>
<row>
<col>TRAINING TITLE</col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col><![CDATA[<p><strong> Domestic Appliance Servicing</strong></p>]]></col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col><![CDATA[<em>  Version 4.6 September 2011</em>]]></col>
</row>
</Item>
<Item Description="Copyright Page - Advanced Table QA39" ID="cacms^2880" Title="Copyright Page - QA 39/01 copyright text" Type="Advanced Table">
<row>
<col><![CDATA[<p> </p><p>Published by: </p><p>TTT, </p><p>P.O. Box 1, </p><p>TTTT Street, </p><p>TT, TT</p><p>© TT 2011<br /></p>]]></col>
</row>
<row>
<col><![CDATA[The copyright of this document is the property of TT except where copyright is acknowledged to belong to a third party.]]></col>
</row>
<row>
<col><![CDATA[ ]]></col>
</row>
<row>
<col>All rights reserved. </col>
</row>
<row>
<col><![CDATA[<b><font size="2" face="Arial-BoldMT"><font size="2" face="Arial-BoldMT"><p align="left"> </p></font></font></b>]]></col>
</row>
</Item>
</ObjectData>
</Object>
</StructureData>
如何编写XSLT来提取每次构造为不同树的XML数据(主要来自属性)
您只需为xsd规则集文档中的每种类型编写一个xslt,并将其应用于实例