我对 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" />
.
为什么会这样?有人可以帮我理解吗?