Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 使用XSLT/Xpath打印值_Xml_Xslt_Xpath - Fatal编程技术网

Xml 使用XSLT/Xpath打印值

Xml 使用XSLT/Xpath打印值,xml,xslt,xpath,Xml,Xslt,Xpath,我正在使用XSLT处理一个XML文档,但我无法让它正常工作 这是我的简单XSLT文档。我使用了W3学校的模板 <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body&g

我正在使用XSLT处理一个XML文档,但我无法让它正常工作

这是我的简单XSLT文档。我使用了W3学校的模板

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h1>VAT No.:</h1>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Prefix</th>
        <th>Number</th>
      </tr>
      <tr>
        <td><xsl:value-of select="/document/page/body/dd[1]/dd[1]/dd/table/cell[1]/para[1]/ln[1]/wd[3]" /></td>
        <td><xsl:value-of select="/document/page/body/dd[1]/dd[1]/dd/table/cell[1]/para[1]/ln[1]/wd[4]" /></td>
      </tr>
    </table> 
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

增值税编号:
前缀
数
正如你所看到的,我只是想展示给出的两个词。我只将其保留为表格格式,以便尽可能少地更改w3schools的原始代码

我没有在表中显示这两个词,而是得到了以下结果:

除非有什么愚蠢的事情,否则我会错过,XPath是正确的。我甚至使用了一个在线Xpath查看器来确认它。 我已经尝试了/、*和//的各种放置方式。以及编辑该行

下面是输入XML的一部分。这是不完整的,因为有一些敏感信息,但您可以看到布局

<?xml version="1.0" encoding="UTF-16"?>
<?xml-stylesheet href="XSLT Stylesheet.XSL" type="text/xsl"?>
<!--XML document generated using OCR technology from Nuance Communications, Inc.-->
<document xmlns="http://www.scansoft.com/omnipage/xml/ssdoc-schema3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<page ocr-vers="OmniPageCSDK18" app-vers="OmniPage 19">
<description>
<source file="C:\Users\dan\Pictures\7740411202.jpg" dpix="300" dpiy="300" sizex="3375" sizey="2330"/>
<theoreticalPage size="Custom" marginLeft="134" marginTop="40" marginRight="45" marginBottom="1184" offsetY="-84" width="16200" height="11184"/>
<language>en</language>
</description>
<body>
<section l="14275" t="40" r="15715" b="228">
<column l="14275" t="40" r="15715" b="228">
<para l="14308" t="84" r="15697" b="197" alignment="left" spaceBefore="2" lsp="exactly" lspExact="174" language="en">
<tabs position="14308"/>
<ln l="14669" t="84" r="15631" b="197" baseLine="182">
<run underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c"><wd l="0" t="0" r="0" b="0">Page</wd>
<tab position="14669"/>
</run>
<run underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c"><wd l="15185" t="89" r="15218" b="194">1</wd>
<space/>
<wd l="15326" t="84" r="15470" b="197">of</wd>
<space/>
<wd l="15595" t="89" r="15631" b="194">1</wd>
</run>
</ln>
</para>
</column>
</section>
<dd l="139" t="266" r="8777" b="3762">
<dd l="4297" t="266" r="8777" b="1807" backColor="d3d3d2" bottomDistance="375">
<bottomBorder type="single" width="2" color="d7d7d7"/>
<dd l="4297" t="266" r="8777" b="1807">
<table l="4297" t="266" r="8777" b="1803" alignment="left">
<gridTable>
<gridCol>3899</gridCol>
<gridCol>581</gridCol>
<gridRow>1537</gridRow>
</gridTable>
<cell gridColFrom="0" gridColTill="0" gridRowFrom="0" gridRowTill="0" alignment="left" verticalAlignment="top">
<para l="4373" t="367" r="6322" b="679" alignment="left" li="72" spaceBefore="53" lsp="exactly" lspExact="197" language="en">
<ln l="4373" t="367" r="6322" b="482" baseLine="480" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c" forcedEOF="true">
<wd l="4373" t="367" r="4572" b="480">HP</wd>
<space/>
<wd l="4618" t="367" r="4944" b="480">VAT</wd>
<space/>
<wd l="4985" t="370" r="5213" b="482">No:</wd>
<space/>
<wd l="5388" t="367" r="6322" b="480">GB31414xxx
</wd>
</ln>
<ln l="4373" t="562" r="5738" b="679" baseLine="677" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c" forcedEOF="true">
<wd l="4373" t="562" r="5446" b="679">Hewlett-Packard</wd>
<space/>
<wd l="5491" t="562" r="5738" b="677">Ltd.</wd>
</ln>
</para>
<para l="4375" t="744" r="7368" b="1042" alignment="left" li="72" ri="828" lsp="exactly" lspExact="182" language="en">
<ln l="4375" t="744" r="7368" b="883" baseLine="859" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="-2" foreColor="0c0c0c">
<wd l="4375" t="744" r="4673" b="859">Cxxx</wd>
<space/>
<wd l="4718" t="744" r="5083" b="883">Rxxx,</wd>
<space/>
<wd l="5134" t="749" r="5522" b="862">Axxxx</wd>
<space/>
<wd l="5566" t="746" r="6007" b="859">Cxxxxx</wd>
<space/>
<wd l="6055" t="746" r="6701" b="883">Bracknell,</wd>
<space/>
<wd l="6754" t="744" r="7368" b="859">Berkshire</wd>
<space/>
</ln>
<ln l="4375" t="929" r="5100" b="1042" baseLine="1042" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="-2" foreColor="0c0c0c">
<wd l="4375" t="929" r="4747" b="1042">Rxxx</wd>
<space/>
<wd l="4812" t="929" r="5100" b="1042">1xx</wd>
</ln>
</para>
<para l="4375" t="1169" r="5590" b="1282" alignment="left" li="72" spaceBefore="61" lsp="exactly" lspExact="179" language="en">
<ln l="4375" t="1169" r="5590" b="1282" baseLine="1282" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c">
<wd l="4375" t="1169" r="4901" b="1282">GREAT</wd>
<space/>
<wd l="4949" t="1171" r="5590" b="1282">BRITAIN</wd>
</ln>
</para>
<para l="4375" t="1406" r="6528" b="1550" alignment="left" li="72" spaceBefore="61" spaceAfter="242" lsp="exactly" lspExact="179" language="en">
<ln l="4375" t="1406" r="6528" b="1550" baseLine="1522" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c">
<wd l="4375" t="1406" r="4766" b="1522">Phone</wd>
<space/>
<wd l="4810" t="1406" r="5366" b="1522">Number:</wd>
<space/>
<wd l="5395" t="1411" r="5597" b="1550">(44</wd>
<space/>
<wd l="5664" t="1409" r="6007" b="1550">1xxx)</wd>
<space/>
<wd l="6062" t="1409" r="6528" b="1522">36xxxxx</wd>
</ln>
</para>
</cell>
<cell gridColFrom="1" gridColTill="1" gridRowFrom="0" gridRowTill="0" alignment="centered" verticalAlignment="top">
<picture l="8196" t="305" r="8738" b="1769" alignment="centered" ri="39" spaceBefore="39" spaceAfter="34">
</picture>
</cell>
</table>
</dd>
</dd>
<dd l="4297" t="2182" r="8777" b="3762">
<para l="6444" t="2215" r="8683" b="2345" alignment="justified" li="2088" lsp="exactly" lspExact="207" language="en">
<ln l="6444" t="2215" r="8683" b="2345" baseLine="2342">
<run bold="true" underlined="none" subsuperscript="none" fontSize="900" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="7" foreColor="0c0c0c"><wd l="6444" t="2218" r="7390" b="2345">DELIVERY</wd>
<space/>
</run>
<run bold="true" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="7" foreColor="0c0c0c"><wd l="7447" t="2220" r="7692" b="2342">TO</wd>
<space/>
<wd l="7795" t="2220" r="8683" b="2342">0000610727</wd>
</run>
</ln>
</para>
<para l="6449" t="2496" r="7646" b="2628" alignment="justified" li="2088" spaceBefore="84" lsp="exactly" lspExact="195" language="en">
<ln l="6449" t="2496" r="7646" b="2628" baseLine="2626">
<run bold="true" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="2" foreColor="0c0c0c"><wd l="6449" t="2496" r="7034" b="2628">Cxxxxx</wd>
<space/>
<wd l="7082" t="2503" r="7246" b="2626">IT</wd>
<space/>
</run>
<run underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="2" foreColor="0c0c0c"><wd l="7298" t="2506" r="7646" b="2626">Parts</wd>
</run>
</ln>
</para>
<para l="6444" t="2736" r="7258" b="2868" alignment="justified" li="2088" spaceBefore="38" lsp="exactly" lspExact="207" language="en">
<ln l="6444" t="2736" r="7258" b="2868" baseLine="2866" underlined="none" subsuperscript="none" fontSize="900" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c">
<wd l="6444" t="2736" r="6936" b="2868">xxxxxx</wd>
<space/>
<wd l="6982" t="2741" r="7258" b="2868">Hse</wd>
</ln>
</para>
<para l="6449" t="2976" r="7219" b="3108" alignment="justified" li="2088" spaceBefore="35" lsp="exactly" lspExact="207" language="en">
<ln l="6449" t="2976" r="7219" b="3108" baseLine="3108" underlined="none" subsuperscript="none" fontSize="900" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c">
<wd l="6449" t="2976" r="6965" b="3108">Oxxxx</wd>
<space/>
<wd l="7010" t="2976" r="7219" b="3108">Rd</wd>
</ln>
</para>
<para l="6454" t="3218" r="8198" b="3348" alignment="justified" li="2088" spaceBefore="31" lsp="exactly" lspExact="207" language="en">
<ln l="6454" t="3218" r="8198" b="3348" baseLine="3346">
<run underlined="none" subsuperscript="none" fontSize="900" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="1" foreColor="0c0c0c"><wd l="6454" t="3218" r="6739" b="3348">SL9</wd>
<space/>
<wd l="6794" t="3218" r="7745" b="3348">7Bxxxx</wd>
<space/>
</run>
<run underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="1" foreColor="0c0c0c"><wd l="7805" t="3223" r="8198" b="3346">Cross</wd>
</run>
</ln>
</para>
<para l="6449" t="3458" r="7810" b="3588" alignment="justified" li="2088" spaceBefore="33" spaceAfter="125" lsp="exactly" lspExact="207" language="en">
<ln l="6449" t="3458" r="7810" b="3588" baseLine="3586" underlined="none" subsuperscript="none" fontSize="900" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="0" foreColor="0c0c0c">
<wd l="6449" t="3458" r="7042" b="3588">GREAT</wd>
<space/>
<wd l="7092" t="3463" r="7810" b="3586">BRITAIN</wd>
</ln>
</para>
</dd>
<dd l="139" t="266" r="689" b="962">
<picture l="139" t="413" r="689" b="962" alignment="left" spaceBefore="147">
</picture>
</dd>
<dd l="139" t="2279" r="2508" b="3762">
<para l="149" t="2302" r="2105" b="2424" alignment="justified" lsp="exactly" lspExact="185" language="en">
<ln l="149" t="2302" r="2105" b="2424" baseLine="2422" bold="true" underlined="none" subsuperscript="none" fontSize="800" fontFace="Times New Roman" fontFamily="roman" fontPitch="variable" spacing="16" foreColor="0c0c0c">
<wd l="149" t="2302" r="518" b="2422">VAT</wd>
<space/>
<wd l="574" t="2304" r="833" b="2424">No:</wd>
<space/>
<wd l="1054" t="2302" r="2105" b="2424">GB530000000</wd>
</ln>
</para>

EN
页
1.
属于
1.
3899
581
1537
惠普
增值税
不:
GB31414xxx
惠普
有限公司。
Cxxx
Rxxx,
Axxxx
Cxxxxx
布雷克内尔,
伯克希尔
Rxxx
1xx
伟大的
英国
电话
编号:
(44
1xxx)
36xxxxx
传送
到
0000610727
Cxxxxx
信息技术
部分
xxxxxx
健康安全环保
程序文件名
研发部
SL9
7Bxxxx
交叉
伟大的
英国
增值税
不:
GB530000000

您能展示一个输入XML的示例吗?该声明将文档中所有未加前缀的元素名称放在一个名称空间中,因此您需要在XSLT中为该名称空间分配一个前缀,然后在XPath表达式中使用前缀“我如何更改它以使我不需要这样做?”@Dan您不能在XSLT(1.0)中使用,您必须编辑输入XML文件以删除名称空间声明。如果您有权访问XSLT2.0,那么可以使用
xpath默认名称空间
,但这在1.0中不可用(鉴于您使用了
,我确实有能力编辑输入XML文件。这是否像在开头添加一行那么简单?@Dan用
替换整个开头的
标记就足够了。谢谢,这样做对文档有什么不利之处吗?
<document xmlns="http://www.scansoft.com/omnipage/xml/ssdoc-schema3.xsd"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:ss="http://www.scansoft.com/omnipage/xml/ssdoc-schema3.xsd">

  <!-- ... -->
  <td><xsl:value-of select="/ss:document/ss:page/ss:body/ss:dd[1]/ss:dd[1]/ss:dd/ss:table/ss:cell[1]/ss:para[1]/ss:ln[1]/ss:wd[3]" /></td>
<xsl:value-of select="//ss:wd[preceding-sibling::ss:wd[2] = 'VAT']
                             [preceding-sibling::ss:wd[1] = 'No:']" />