0
我正在嘗試使用XSLT和css實現xml文件的樹視圖。 我有嵌套的孩子在XML中,我遍歷他們來顯示每個條目的內容。如何在XSLT上動態設置保證金
每個孩子都是一個帶有消息條目的記錄器。我希望每個子表根據祖先計數縮進,我得到正確。然而試圖動態設置表格邊距margin-left =「$ margin * 10」不起作用。
這是我的XSLT/XML
<xsl:template match="operationLogger">
<xsl:variable name="margin" select="count(ancestor::*) * 10"/>
<table class="normalTable" cols="4">
<xsl:attribute name="margin-left">
<xsl:value-of select="$margin"/>
</xsl:attribute>
<tr class="errorsCollectionTitle">
<td colspan="4">
<xsl:value-of select="@name"/>
</td>
</tr>
<xsl:if test="operationLogEntry">
<xsl:apply-templates select="operationLogEntry"/>
</xsl:if>
<xsl:if test="operationLogger">
<xsl:apply-templates select="operationLogger"/>
</xsl:if>
</table>
</xsl:template>
<xsl:template match="operationLogEntry">
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="position() mod 2 = 1">rowData</xsl:when>
<xsl:otherwise>rowAlternatingData</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<td>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@level = 'Error'">errorImage</xsl:when>
<xsl:when test="@level = 'Warning'">warningImage</xsl:when>
<xsl:when test="@level = 'Info'">informationImage</xsl:when>
<xsl:when test="@level = 'Debug'">informationImage</xsl:when>
</xsl:choose>
</xsl:attribute>
</td>
<td class="timeStamp">
<xsl:value-of select="@timeStamp"/>
</td>
<td class="source">
<xsl:value-of select="../loggerSource/@computer" />
/
<xsl:value-of select="../loggerSource/@user" />
</td>
<td class="message">
<div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@level = 'Error'">errorColor</xsl:when>
<xsl:when test="@level = 'Warning'">warningColor</xsl:when>
<xsl:when test="@level = 'Info'">informationColor</xsl:when>
<xsl:when test="@level = 'Debug'">informationColor</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="@message"/>
</div>
</td>
</tr>
</xsl:template>
<operationLogger name="">
<loggerSource domain="user" computer="computer" user="account" />
<operationLogEntry timeStamp="2015/02/16 07:15:21" level="Info" message="Adding 1 to transactions list" />
<operationLogEntry timeStamp="2015/02/16 07:15:21" level="Info" message="Executing 1 transactions..." />
<operationLogEntry timeStamp="2015/02/16 07:15:22" level="Info" message="Executed 1 transactions successfully!" />
<operationLogger name="TransactionOperationCollection.Execute()">
<loggerSource domain="user" computer="computer" user="account" />
<operationLogEntry timeStamp="2015/02/16 07:15:21" level="Info" message="Commiting transaction 0:Transaction" />
<operationLogEntry timeStamp="2015/02/16 07:15:22" level="Info" message="Committed transaction 0:Transaction" />
<operationLogger name="TransactionOperation.Commit()">
<operationLogEntry timeStamp="2015/02/16 07:15:22" level="Info" message="Setting Auditonly" />
<operationLogEntry timeStamp="2015/02/16 07:15:22" level="Info" message="Succesfully changed Audit Only" />
</operationLogger>
</operationLogger>
</operationLogger>
,我試圖從1到循環 '的祖先號' 和增加跨度或股利。我嘗試推送第一行的內容。沒有什麼似乎爲我工作。
任何幫助將不勝感激!
非常感謝!我不敢相信我浪費了太多的時間來使用內聯屬性而不是使用樣式!你是救世主! – Roussul 2015-03-16 12:37:15