Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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
Python XLS转换,请求子节点数据_Python_Xml_Xslt - Fatal编程技术网

Python XLS转换,请求子节点数据

Python XLS转换,请求子节点数据,python,xml,xslt,Python,Xml,Xslt,我刚刚开始使用XLS转换——我想使用它们在我的项目中添加额外的抽象层。 我想使用转换将crystal reports生成的xml文件转换为另一个xml,为我的项目简化(所以将来,当文件的模式发生变化时,我只需要更改xsl文件) 因此,我的输入xml文件如下所示: <CrystalReport xmlns="urn:crystal-reports:schemas:report-detail" xmlns:xsi="http://www.w3.org/2001

我刚刚开始使用XLS转换——我想使用它们在我的项目中添加额外的抽象层。 我想使用转换将crystal reports生成的xml文件转换为另一个xml,为我的项目简化(所以将来,当文件的模式发生变化时,我只需要更改xsl文件)

因此,我的输入xml文件如下所示:

<CrystalReport xmlns="urn:crystal-reports:schemas:report-detail"  
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xsi:schemaLocation="urn:crystal-reports:schemas:report-detail http://www.businessobjects.com/products/xml/CR2008Schema.xsd">
    <Group Level="1">
        <GroupHeader>
            <Section SectionNumber="0">
                <Field Name="Field4" FieldName="{@PartIndex}"><FormattedValue>Part Number</FormattedValue><Value>51-01672</Value></Field>
            </Section>
            <Section SectionNumber="1">
                <Text Name="Text28"><TextValue>Part Description</TextValue>
                </Text>
            </Section>
            <Section SectionNumber="2">
                <Text Name="Text21"><TextValue>Part Description 2</TextValue>
                </Text>
            </Section>
            <Section SectionNumber="3">
            </Section>
...

零件号51-01672
零件说明
零件说明2
...
这只是其中的一部分。我应该提到的是,GroupHeader节点在组节点内部不重复

所以我做了一些早期的xsl定义(为了测试):


我使用lxmlpythonlib来测试它。 这将按预期返回以下代码:

<ToolsUsage xmlns:t="urn:crystal-reports:schemas:report-detail" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1</ToolsUsage>
1
到目前为止,还不错(对于第一个组节点,级别属性等于“1”)。但我不能再往前走了。 例如,我尝试获取字段节点(第一节出现)的值内部文本:


但是我没有得到任何东西(结果是在节点中)。我尝试获取SectionNumber属性,但也没有结果。我甚至使用xml路径工具来提取精确的xpath查询,但似乎查询是正确的。我相信这是非常基本的,但找不到什么。

给定
..
,所有子元素也都在名称空间中,因此您的路径需要在所有元素上使用前缀,例如
t:Group[1]/t:GroupHeader/t:Section[1]/t:Field/t:Value

<ToolsUsage xmlns:t="urn:crystal-reports:schemas:report-detail" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1</ToolsUsage>
<xsl:value-of select="t:Group[1]/GroupHeader/Section[1]/Field/Value"/>