以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML源码及示例(仅原创和转载) 』  (http://bbs.xml.org.cn/list.asp?boardid=32)
----  请教一个execl 的xml格式转换问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=32&rootid=&id=11092)


--  作者:nick-you
--  发布时间:10/18/2004 10:41:00 AM

--  请教一个execl 的xml格式转换问题
我想做的是把excel 的xml格式,如下:
<?xml version="1.0"?>
<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>Administrator</Author>
  <LastAuthor>Administrator</LastAuthor>
  <Created>2004-10-13T02:15:57Z</Created>
  <LastSaved>2004-10-13T02:27:07Z</LastSaved>
  <Version>10.2625</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
  <DownloadComponents/>
  <LocationOfComponents HRef="file:///\\172.17.16.82\f\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>9000</WindowHeight>
  <WindowWidth>14940</WindowWidth>
  <WindowTopX>240</WindowTopX>
  <WindowTopY>30</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Center"/>
   <Borders/>
   <Font ss:FontName="宋体" x:CharSet="134" ss:Size="12"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
</Styles>
<Worksheet ss:Name="Sheet1">
  <Table ss:ExpandedColumnCount="7" ss:ExpandedRowCount="20" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25">
   <Row ss:AutoFitHeight="0">
    <Cell><Data ss:Type="String">测试文字</Data></Cell>
   </Row>
   <Row ss:AutoFitHeight="0">
    <Cell ss:Index="2"><Data ss:Type="String">文档化</Data></Cell>
    <ss:Hidden ss:Index="1">
      <ss:Data ss:Type="String">将要hidden</ss:Data>
     </ss:Hidden>
   </Row>
   <Row ss:AutoFitHeight="0" ss:Span="1"/>
   <Row ss:Index="5" ss:AutoFitHeight="0">
    <Cell ss:Index="7"><Data ss:Type="String">是什么</Data></Cell>
   </Row>
   <Row ss:AutoFitHeight="0" ss:Span="1"/>
   <Row ss:Index="8" ss:AutoFitHeight="0">
    <Cell ss:Index="4"><Data ss:Type="String">客户化</Data></Cell>
   </Row>
   <Row ss:AutoFitHeight="0" ss:Span="4"/>
   <Row ss:Index="14" ss:AutoFitHeight="0">
    <Cell ss:Index="2"><Data ss:Type="String">不知道</Data></Cell>
   </Row>
   <Row ss:AutoFitHeight="0" ss:Span="1"/>
   <Row ss:Index="17" ss:AutoFitHeight="0">
    <Cell ss:Index="5"><Data ss:Type="String">的</Data></Cell>
   </Row>
   <Row ss:AutoFitHeight="0" ss:Span="1"/>
   <Row ss:Index="20" ss:AutoFitHeight="0">
    <Cell ss:Index="2"><Data ss:Type="Number">11111</Data></Cell>
   </Row>
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Unsynced/>
   <Selected/>
   <TopRowVisible>3</TopRowVisible>
   <Panes>
    <Pane>
     <Number>3</Number>
     <ActiveRow>19</ActiveRow>
     <ActiveCol>1</ActiveCol>
    </Pane>
   </Panes>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet2">
  <Table ss:ExpandedColumnCount="0" ss:ExpandedRowCount="0" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25"/>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Unsynced/>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet3">
  <Table ss:ExpandedColumnCount="0" ss:ExpandedRowCount="0" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25"/>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Unsynced/>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
</Worksheet>
</Workbook>
用xslt转换:xslt的写法如下:<?xml version="1.0" encoding="gb2312"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<schedules>
<schedule>
<header>
<id>0001</id>
<name>testschedule</name>
<Brand>Brand</Brand>
<Category>Category</Category>
</header>
<detail>
<tasks>
<xsl:for-each select="//Workbook/Worksheet/Table/Row" >

  <task>
        <Seq>001</Seq>
 <TaskName>taskname</TaskName>
        <ParentName>parentname</ParentName>
 <Action>delete</Action>
 <Status>status</Status>
 <Attachment>Attachment</Attachment>
 <AssignedRule>AssignedRule</AssignedRule>
 <Discussion>Discussion</Discussion>
 <CompleteDate>CompleteDate</CompleteDate>
 <ResponsibleParty></ResponsibleParty>
 <ScheduleDueDate>ScheduleDueDate</ScheduleDueDate>
 <ViewBy></ViewBy>
 <Duration></Duration>
 <MaterialFabric></MaterialFabric>
 <MillOrVendor></MillOrVendor>
 <Color></Color>
 <Dependency>Dependency</Dependency>
  </task>

  </xsl:for-each>
</tasks>
</detail>
</schedule>
</schedules>
</xsl:template>
</xsl:transform>

问题:怎样<xsl:for-each select="//Workbook/Worksheet/Table/Row" >
不能定位,我想把里面的内容取出,请教一下,怎样定位?


--  作者:doubleG
--  发布时间:10/18/2004 11:28:00 AM

--  
要加入对应的名称空间,才可以处理。

[此贴子已经被作者于2004-10-18 14:40:14编辑过]

--  作者:doubleG
--  发布时间:10/18/2004 2:36:00 PM

--  
详细方法:
你要保证操作的元素的名称空间的正确性。
因为在xml文件中,Workbook的默认名称空间是xmlns="urn:schemas-microsoft-com:office:spreadsheet"
所以在xslt文件中要声明这个名称空间。

>><?xml version="1.0" encoding="gb2312"?>
>><xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    改成:
   <xsl:transform version="1.0"
    xmlns:myExcel=="urn:schemas-microsoft-com:office:spreadsheet"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
然后在选取的时候要加上这个名称前缀:
>><xsl:template match="/">
>><schedules>
>><schedule>
>><header>
>><id>0001</id>
>><name>testschedule</name>
>><Brand>Brand</Brand>
>><Category>Category</Category>
>></header>
>><detail>
>><tasks>
>><xsl:for-each select="//Workbook/Worksheet/Table/Row" >
     改为:
    <xsl:for-each select="//myExcel:Workbook/myExcel:Worksheet/myExcel:Table/myExcel:Row">
>><task>
>>       <Seq>001</Seq>
>><TaskName>taskname</TaskName>
>>       <ParentName>parentname</ParentName>
>> <Action>delete</Action>
>> <Status>status</Status>
>> <Attachment>Attachment</Attachment>
>> <AssignedRule>AssignedRule</AssignedRule>
>> <Discussion>Discussion</Discussion>
>> <CompleteDate>CompleteDate</CompleteDate>
>> <ResponsibleParty></ResponsibleParty>
>> <ScheduleDueDate>ScheduleDueDate</ScheduleDueDate>
>> <ViewBy></ViewBy>


--  作者:nick-you
--  发布时间:10/19/2004 5:01:00 PM

--  
非常感谢你的帮忙,有QQ吗,交个朋友? 我的QQ 17165377
--  作者:doubleG
--  发布时间:10/22/2004 2:34:00 PM

--  
呵呵,QQ牺牲了呢。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms