【问题标题】:XSLT Unexpected token beyond end of expressionXSLT 超出表达式结尾的意外标记
【发布时间】:2019-07-04 03:38:38
【问题描述】:

这是从 Excel 文档转换而来的源 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>Passiflora Cui</Author>
  <LastAuthor>Passiflora Cui</LastAuthor>
  <Created>2019-06-30T21:49:41Z</Created>
  <LastSaved>2019-06-30T21:50:54Z</LastSaved>
  <Version>16.00</Version>
 </DocumentProperties>
 <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
  <AllowPNG/>
 </OfficeDocumentSettings>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>16940</WindowHeight>
  <WindowWidth>27640</WindowWidth>
  <WindowTopX>5580</WindowTopX>
  <WindowTopY>3560</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="12" ss:Color="#000000"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s62">
   <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Sheet1">
  <Table ss:ExpandedColumnCount="4" ss:ExpandedRowCount="5" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="65" ss:DefaultRowHeight="16">
   <Column ss:AutoFitWidth="0" ss:Width="74"/>
   <Row>
    <Cell><Data ss:Type="String">Field1</Data></Cell>
    <Cell><Data ss:Type="String">Field2</Data></Cell>
    <Cell><Data ss:Type="String">Field3</Data></Cell>
    <Cell><Data ss:Type="String">Field4</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">Field1_Data1</Data></Cell>
    <Cell ss:StyleID="s62"><Data ss:Type="String">Field2_Data1</Data></Cell>
    <Cell><Data ss:Type="String">Field3_Data1</Data></Cell>
    <Cell><Data ss:Type="String">Field4_Data1</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">Field1_Data2</Data></Cell>
    <Cell ss:StyleID="s62"><Data ss:Type="String">Field2_Data2</Data></Cell>
    <Cell><Data ss:Type="String">Field3_Data2</Data></Cell>
    <Cell><Data ss:Type="String">Field4_Data2</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">Field1_Data3</Data></Cell>
    <Cell ss:StyleID="s62"><Data ss:Type="String">Field2_Data3</Data></Cell>
    <Cell><Data ss:Type="String">Field3_Data3</Data></Cell>
    <Cell><Data ss:Type="String">Field4_Data3</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">Field1_Data4</Data></Cell>
    <Cell ss:StyleID="s62"><Data ss:Type="String">Field2_Data4</Data></Cell>
    <Cell><Data ss:Type="String">Field3_Data4</Data></Cell>
    <Cell><Data ss:Type="String">Field4_Data4</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>5</ActiveRow>
     <ActiveCol>5</ActiveCol>
    </Pane>
   </Panes>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>

这是我的 XSLT,从将 Excel XML 文件转换为 Word XML 文件的较大文件中提取了问题部分,其中 &lt;a:ext&gt;&lt;/a:ext&gt; 元素导致错误:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:wb="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
    <xsl:output method = "xml" indent = "yes"/>

    <!-- Ignore all free text() nodes -->
    <xsl:template match="text()" />

    <xsl:template match = "/wb:Workbook/wb:Worksheet/wb:Table">
        <pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
            <Result>
                <xsl:for-each select="wb:Row[position() > 1]">
                    <Test>
                        <Field1><xsl:value-of select = "wb:Cell[1]/wb:Data"/></Field1>
                        <Field2><xsl:value-of select = "wb:Cell[2]/wb:Data"/></Field2>
                        <Field3><xsl:value-of select = "wb:Cell[3]/wb:Data"/></Field3>
                        <Field4><xsl:value-of select = "wb:Cell[4]/wb:Data"/></Field4>
                    </Test>
                </xsl:for-each>
            </Result>
            <!--The following a:ext element is just directly copied to the result, which causes the errors-->
            <a:ext uri="{05A4C25C-085E-4340-85A3-A5531E510DB2}">
                <thm15:themeFamily xmlns:thm15="http://schemas.microsoft.com/office/thememl/2012/main" name="Office Theme" id="{62F939B6-93AF-4DB8-9C6B-D6C7DFDC589F}" vid="{4A3C46E8-61CC-4603-A589-7422A47A8E4A}"/>
            </a:ext>
        </pkg:package>
    </xsl:template>
</xsl:stylesheet>

&lt;a:ext&gt;&lt;/a:ext&gt; 元素是从 Word XML 复制而来,只想直接复制到结果中。但是报错“Unexpected token &lt;name&gt; beyond end of expression”,完整的错误信息如下:

Severity: warning
Description: Error in expression 05A4C25C-085E-4340-85A3-A5531E510DB2: Unexpected token <name> beyond end of expression
Start location: 22:0

Severity: warning
Description: Error in expression 62F939B6-93AF-4DB8-9C6B-D6C7DFDC589F: Unexpected token <name> beyond end of expression
Start location: 23:0

Severity: warning
Description: Error in expression 4A3C46E8-61CC-4603-A589-7422A47A8E4A: Unexpected token <name> beyond end of expression
Start location: 23:0

如何解决这个问题?提前感谢您的帮助!

【问题讨论】:

    标签: excel xml xslt ms-word


    【解决方案1】:

    属性中的花括号表示内容将被视为要评估的 XPATH 表达式。为了得到你想要的,你需要加倍大括号来逃避它们:

            <a:ext uri="{{05A4C25C-085E-4340-85A3-A5531E510DB2}}">
                <thm15:themeFamily 
                    xmlns:thm15="http://schemas.microsoft.com/office/thememl/2012/main" 
                    name="Office Theme" 
                    id="{{62F939B6-93AF-4DB8-9C6B-D6C7DFDC589F}}" 
                    vid="{{4A3C46E8-61CC-4603-A589-7422A47A8E4A}}"/>
            </a:ext>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 2022-07-01
      • 1970-01-01
      • 2014-11-12
      相关资源
      最近更新 更多