1

编辑:看来我的软件只支持 XPath 1.0。:(

我需要创建以下格式的分隔字符串:

Stuff,Things;A,1;B,2

来自以下 XML 数据:

<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="3" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15">
 <Row>
  <Cell><Data ss:Type="String">Stuff</Data></Cell>
  <Cell><Data ss:Type="String">Things</Data></Cell>
 </Row>
 <Row>
  <Cell><Data ss:Type="String">A</Data></Cell>
  <Cell><Data ss:Type="Number">1</Data></Cell>
 </Row>
 <Row>
  <Cell><Data ss:Type="String">B</Data></Cell>
  <Cell><Data ss:Type="Number">2</Data></Cell>
 </Row>
</Table>

列用 表示,,行用 表示;。这应该创建一个二维数组。

- - - - -笔记 - - - - - -

我已经针对示例 XML 尝试了以下表达式,但在使用 NotePad++ XPatherizerNPP 应用时它不起作用:

eval(eval(Row, 'concat(Cell, ";")'), "..")

上面的表达式会引发以下错误:XSLTContext is needed for this query because of an unknown function

“Eval”函数通常在 MS InfoPath 中工作,但 XPatherizer 可能不会以与 InfoPath 相同的方式处理 XPath。也有可能是我不理解这句话的上下文,我使用不当。

作为旁注,是否有任何好的 Web 资源可以解释 XPath Eval 的使用?我不完全理解它,似乎找不到任何好的解释。

--------完整的XML--------

这是我尝试使用的 XML 的全文。它是由 MS Excel 生成的“XML 电子表格”。我无权创建自定义 XML 映射,因为我无权在我的系统上安装 XML 工具。

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <Author>Smith, Robert;-</Author>
  <LastAuthor>Smith, Robert;-</LastAuthor>
  <Created>2013-08-27T16:29:45Z</Created>
  <Company>SmithWorks</Company>
  <Version>14.00</Version>
 </DocumentProperties>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>10035</WindowHeight>
  <WindowWidth>22035</WindowWidth>
  <WindowTopX>240</WindowTopX>
  <WindowTopY>90</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Sheet1">
  <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="3" x:FullColumns="1"
   x:FullRows="1" ss:DefaultRowHeight="15">
   <Row>
    <Cell><Data ss:Type="String">Stuff</Data></Cell>
    <Cell><Data ss:Type="String">Things</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">A</Data></Cell>
    <Cell><Data ss:Type="Number">1</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">B</Data></Cell>
    <Cell><Data ss:Type="Number">2</Data></Cell>
   </Row>
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <Selected/>
   <Panes>
    <Pane>
     <Number>3</Number>
     <ActiveRow>3</ActiveRow>
     <ActiveCol>1</ActiveCol>
    </Pane>
   </Panes>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
 <Worksheet ss:Name="Sheet2">
  <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
   x:FullRows="1" ss:DefaultRowHeight="15">
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
 <Worksheet ss:Name="Sheet3">
  <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
   x:FullRows="1" ss:DefaultRowHeight="15">
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>
4

1 回答 1

2

这对我来说似乎很神奇,但我试过了

string-join((for $n in //Row return string-join($n/Cell, ',')), ';')

它的结果就是你所需要的

Stuff,Things;A,1;B,2

编辑:我忘了提到这仅适用于 xpath 2.0

于 2013-08-28T14:09:24.183 回答