2014-12-02 89 views
0

目前,除了一件事情之外,在瀏覽器中顯示XML以及XSL數據是正確的。在一些大學我有一個部門,而我有不止一個部門(多達9個)。我如何根據每所大學的部門數量動態輸出數據?目前它只爲每所大學輸出一個部門。動態更改XSL文件中的值

College.xml文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<?xml-stylesheet type="text/xsl" href="colleges.xsl"?><colleges> 
<college id="0"> 
<school>College of Education</school> 
<mission>text</mission> 
<department id="0">Educational Psychology and Leadership</department> 
<department id="1">Health and Human Performance</department> 
<department id="2">Language, Literacy and Intercultural Studies</department> 
<department id="3">Teaching, Learning and Innovation</department> 
</college> 
<college id="1"> 
<school>College of Nursing</school> 
<mission>text</mission> 
<department id="0">Nursing</department> 
</college> 
<college id="2"> 
<school>School of Business</school> 
<mission>text</mission> 
<department id="0">Accounting and Management Information Systems</department> 
<department id="1">Applied Business Technology</department> 
</college></colleges> 

College.xsl文件:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
<html> 
    <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE"> 
    <xsl:for-each select="colleges/college"> 
     <div style="background-color:teal;color:white;padding:4px"> 
     <span style="font-weight:bold"><xsl:value-of select="school"/></span> - <br /><xsl:value-of select="mission"/> 
     </div> 
     <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> 
     <p> 
     <xsl:value-of select="department"/><br /> 
     </p> 
     </div> 
    </xsl:for-each> 
    </body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 
+0

相反,讓我們猜測,你應該發佈你期望得到的確切輸出。 – 2014-12-02 22:18:52

回答

0

嘗試:

<xsl:template match="/"> ... 
    <xsl:for-each select="colleges/college"> 
     ... 
     <xsl:apply-templates select="department"/> 
     ... 
    </xsl:for-each> 
</xsl:template> 
<xsl:template match="department">... what you want for each department</xsl:template> 
+0

謝謝!有效! – dothack 2014-12-03 02:23:31

0

給這個一杆...

<xsl:template match="/"> 
<html> 
    <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE"> 
    <xsl:for-each select="colleges/college"> 
     <div style="background-color:teal;color:white;padding:4px"> 
     <span style="font-weight:bold"><xsl:value-of select="school"/></span> - <br /><xsl:value-of select="mission"/> 
     </div> 
     <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> 
     <p> 
     <xsl:apply-templates select="department"/> 
     </p> 
     </div> 
    </xsl:for-each> 
    </body> 
</html> 
</xsl:template> 

<xsl:template match="department"> 
    <xsl:value-of select="."/><br /> 
</xsl:template>