我是很新,XSLT,和我有以下煩惱:價值休息
我想有這樣的輸出:
<div class="member">
<h2><a href="#">The First Firm</a></h2>
<div class="slidecontent">
<p>
Adress:<br>
The First Firm<br>
Some Adress 123
</p>
<div class="downloadsection">
Redegørelser og Rapporter/The First Firm/Miljøredegørelse-2011.pdf
</div>
</div>
</div>
<div class="member">
<h2><a href="#">The Second Firm</a></h2>
<div class="slidecontent">
<p>
Adress:<br>
The Second Firm<br>
Some Adress 123
</p>
<div class="downloadsection"></div>
</div>
</div>
我的XML看起來像這樣(第3條線被剝離 - 編者不喜歡他們):
<Template>
<loop name="Rows">
<item>
<loop name="Row">
<item>
<Row.ColumnName>FirmName</Row.ColumnName>
<Row.Value>The First Firm</Row.Value>
<Row.Count>0</Row.Count>
<Column.Count>0</Column.Count>
</item>
<item>
<Row.ColumnName>FirmAdress</Row.ColumnName>
<Row.Value>Some Adress 123</Row.Value>
<Row.Count>0</Row.Count>
<Column.Count>1</Column.Count>
</item>
<item>
<Row.ColumnName>Miljoredegorelse</Row.ColumnName>
<Row.Value>Redegørelser og Rapporter/The First Firm/Miljøredegørelse-2011.pdf</Row.Value>
<Row.Count>0</Row.Count>
<Column.Count>2</Column.Count>
</item>
</loop>
</item>
<item>
<loop name="Row">
<item>
<Row.ColumnName>FirmName</Row.ColumnName>
<Row.Value>The Second Firm</Row.Value>
<Row.Count>0</Row.Count>
<Column.Count>0</Column.Count>
</item>
<item>
<Row.ColumnName>FirmAdress</Row.ColumnName>
<Row.Value>Some Adress 456</Row.Value>
<Row.Count>0</Row.Count>
<Column.Count>1</Column.Count>
</item>
<item>
<Row.ColumnName>Miljoredegorelse</Row.ColumnName>
<Row.Value></Row.Value>
<Row.Count>0</Row.Count>
<Column.Count>2</Column.Count>
</item>
</loop>
</item>
</loop>
</Template>
而XSLT:
<xsl:param name="numcolumns" select="3" />
<xsl:template match="/">
<xsl:apply-templates select="Template" />
</xsl:template>
<xsl:template match="Template">
<xsl:call-template name="MemberList" />
</xsl:template>
<xsl:template name="MemberList">
<xsl:for-each select="loop[@name='Rows']/item[((position() - 1) mod $numcolumns) = 0]">
<xsl:for-each select=".|following-sibling::*[position() < $numcolumns]">
<div class="member">
<h2>
<a href="#">
<xsl:for-each select="loop[@name='Row']/item">
<xsl:if test="Row.ColumnName='FirmName' and string-length(Row.Value)!='0'">
<xsl:apply-templates select="Row.Value" />
</xsl:if>
</xsl:for-each>
</a>
</h2>
<div class="slidecontent">
<p>
<xsl:text>Adress: </xsl:text><br />
<xsl:for-each select="loop[@name='Row']/item">
<xsl:if test="Row.ColumnName='FirmAdress' and string-length(Row.Value)!='0'">
<xsl:apply-templates select="Row.Value" /><br />
</xsl:if>
</xsl:for-each>
</p>
<div>
<xsl:attribute name="class">
<xsl:text>downloadsection</xsl:text>
</xsl:attribute>
<xsl:for-each select="loop[@name='Row']/item">
<xsl:if test="Row.ColumnName='Miljoredegorelse' and string-length(Row.Value)!='0'">
<xsl:apply-templates select="Row.Value" />
</xsl:if>
</xsl:for-each>
</div>
</div>
</div>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
當我從第二家公司輸出Row.Column「Miljoredegorelse」時,輸出中斷。
Row.Value顯示正確 - 但不知何故</div>
事後沒有出去。第一個div <div class="downloadsection">
以某種方式自動閉合,看起來像<div class="downloadsection" />
。
這是爲什麼發生?有人能幫助我理解嗎?
如果使用XSLT 2.0,那麼「XHTML」可作爲輸出方法,並根據http://www.w3.org/TR/xslt-xquery-serialization/#xhtml-output那麼
必須在這種情況下輸出。 –@伊恩羅伯茨 - 這個伎倆!輸出應該是html。並非常感謝您指出其他循環內容。 – Crave
和@TimC - 實際上它是XSLT 2.0,所以xhtml是我正在使用的那個。謝謝。 – Crave