我正在尝试格式化下面的XML数据,因此它在使用XSLT的浏览器中显得非常好。我似乎无法提取行。
我尝试了以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Quickbooks Test</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Column1</th>
<th style="text-align:left">Column2</th>
</tr>
<xsl:for-each select='//Row[@type="Data"]'>
<tr>
<td><xsl:value-of select="ColData/@value"/></td>
<td><xsl:value-of select="ColData/@value"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
关于如何从ColData节点中提取@value属性的任何建议,理想情况下是两个不错的列?
对不起,如果这很明显!我无法通过搜索找到它......
===== 原始XML数据
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Report xmlns="http://schema.intuit.com/finance/v3">
<Header>
<Time>2016-04-18T12:03:32-07:00</Time>
<ReportName>BalanceSheet</ReportName>
<DateMacro>this fiscal year-to-date</DateMacro>
<ReportBasis>Accrual</ReportBasis>
<StartPeriod>2015-08-01</StartPeriod>
<EndPeriod>2016-04-18</EndPeriod>
<SummarizeColumnsBy>Total</SummarizeColumnsBy>
<Currency>CAD</Currency>
<Option>
<Name>AccountingStandard</Name>
<Value>IFRS</Value>
</Option>
<Option>
<Name>NoReportData</Name>
<Value>false</Value>
</Option>
</Header>
<Columns>
<Column>
<ColTitle/>
<ColType>Account</ColType>
<MetaData>
<Name>ColKey</Name>
<Value>account</Value>
</MetaData>
</Column>
<Column>
<ColTitle>Total</ColTitle>
<ColType>Money</ColType>
<MetaData>
<Name>ColKey</Name>
<Value>total</Value>
</MetaData>
</Column>
</Columns>
<Rows>
<Row type="Section" group="TotalAssets">
<Header>
<ColData value="Assets"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Section" group="OtherCurrentAssets">
<Header>
<ColData value="Current Assets"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Data">
<ColData value="Undeposited Funds" id="3"/>
<ColData value="353847.76"/>
</Row>
<Row type="Section" group="BankAccounts">
<Header>
<ColData value="Cash and cash equivalents"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Data">
<ColData value="Chequing" id="20"/>
<ColData value="-221951.44"/>
</Row>
</Rows>
<Summary>
<ColData value="Total Cash and cash equivalents"/>
<ColData value="-221951.44"/>
</Summary>
</Row>
<Row type="Section" group="AR">
<Header>
<ColData value="Accounts receivable (A/R)"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Data">
<ColData value="Accounts Receivable (A/R)" id="8"/>
<ColData value="29520.17"/>
</Row>
</Rows>
<Summary>
<ColData value="Total Accounts receivable (A/R)"/>
<ColData value="29520.17"/>
</Summary>
</Row>
</Rows>
<Summary>
<ColData value="Total Current Assets"/>
<ColData value="161416.49"/>
</Summary>
</Row>
</Rows>
<Summary>
<ColData value="Total Assets"/>
<ColData value="161416.49"/>
</Summary>
</Row>
<Row type="Section" group="TotalLiabilitiesAndEquity">
<Header>
<ColData value="Liabilities and Equity"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Section" group="OtherCurrentLiabilities">
<Header>
<ColData value="Current Liabilities"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Data">
<ColData value="GST/HST Payable" id="9"/>
<ColData value="22363.06"/>
</Row>
<Row type="Section">
<Header>
<ColData value="Payroll Liabilities" id="46"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Data">
<ColData value="Federal Taxes" id="47"/>
<ColData value="1180.75"/>
</Row>
</Rows>
<Summary>
<ColData value="Total Payroll Liabilities"/>
<ColData value="1180.75"/>
</Summary>
</Row>
<Row type="Section" group="AP">
<Header>
<ColData value="Accounts Payable"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Data">
<ColData value="Accounts Payable (A/P)" id="18"/>
<ColData value="-724.78"/>
</Row>
</Rows>
<Summary>
<ColData value="Total Accounts Payable"/>
<ColData value="-724.78"/>
</Summary>
</Row>
</Rows>
<Summary>
<ColData value="Total Current Liabilities"/>
<ColData value="22819.03"/>
</Summary>
</Row>
<Row type="Section" group="Equity">
<Header>
<ColData value="Equity"/>
<ColData value=""/>
</Header>
<Rows>
<Row type="Data">
<ColData value="Retained Earnings" id="2"/>
<ColData value="32298.57"/>
</Row>
<Row type="Data" group="NetIncome">
<ColData value="Profit for the year"/>
<ColData value="106298.89"/>
</Row>
</Rows>
<Summary>
<ColData value="Total Equity"/>
<ColData value="138597.46"/>
</Summary>
</Row>
</Rows>
<Summary>
<ColData value="Total Liabilities and Equity"/>
<ColData value="161416.49"/>
</Summary>
</Row>
</Rows>
</Report>
答案 0 :(得分:0)
你有两个问题:
您的源XML将其所有元素放在名称空间;您必须在样式表中声明此命名空间,为其分配前缀并在寻址源XML中的元素时使用该前缀。
您为该行的两个单元格选择了相同的值。
请尝试这种方式(假设数据行总是有两个单元格):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://schema.intuit.com/finance/v3">
<xsl:template match="/">
<html>
<body>
<h2>Quickbooks Test</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Column1</th>
<th style="text-align:left">Column2</th>
</tr>
<xsl:for-each select='//ns1:Row[@type="Data"]'>
<tr>
<td><xsl:value-of select="ns1:ColData[1]/@value"/></td>
<td><xsl:value-of select="ns1:ColData[2]/@value"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>