Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
通过XSL将XML转换为表的多嵌套循环_Xml_Xslt - Fatal编程技术网

通过XSL将XML转换为表的多嵌套循环

通过XSL将XML转换为表的多嵌套循环,xml,xslt,Xml,Xslt,感谢您的支持,现在我能够通过XSLT将xml转换为表,但是,当我添加一个嵌套循环时,结果并没有完全加载,我不确定出了什么问题 数据XML <Records> <Person id="756252" date="15-Oct-2014"> <Gender>Male</Gender> <NameDetails> <Name NameType="Primary Name"&

感谢您的支持,现在我能够通过XSLT将xml转换为表,但是,当我添加一个嵌套循环时,结果并没有完全加载,我不确定出了什么问题

数据XML

<Records>
    <Person id="756252" date="15-Oct-2014">
        <Gender>Male</Gender>
        <NameDetails>
            <Name NameType="Primary Name">
                <NameValue>
                    <FirstName>Ken</FirstName>
                    <Surname>Wu</Surname>
                </NameValue>
            </Name>
            <Name NameType="AKA">
                <NameValue>
                    <FirstName>Kenneth</FirstName>
                    <Surname>Wu</Surname>
                </NameValue>
            </Name>
            <Name NameType="AKA2">
                <NameValue>
                    <FirstName>CAN</FirstName>
                    <Surname>Wu</Surname>
                </NameValue>
            </Name>
        </NameDetails>
        <Descriptions>
            <Description Description1="11" Description2="12" Description3="13"/>
            <Description Description1="21" Description2="22" Description3="23"/>
            <Description Description1="31" Description2="32" Description3="33"/>
        </Descriptions>
        <RoleDetail>
            <Roles RoleType="Primary">
                <OccTitle SinceDay="17" SinceMonth="Nov" SinceYear="2009" OccCat="6">Thai</OccTitle>
            </Roles>
        </RoleDetail>
        <DateDetails>
        <Date DateType="Date of Birth">
            <DateValue Year="1990" />
            <DateValue Year="1991" />
        </Date>
        <Date DateType="Date of Issue">
            <DateValue Year="2000" />
            <DateValue Year="2001" />
        </Date>
        </DateDetails>
    </Person>
    <Person id="253555" date="14-Oct-2014">
        <Gender>Male</Gender>
        <NameDetails>
            <Name NameType="Primary Name">
                <NameValue>
                    <FirstName>Peter</FirstName>
                    <Surname>Lai</Surname>
                </NameValue>
            </Name>
        </NameDetails>
        <Descriptions>
            <Description Description1="11" Description2="12" Description3="13"/>
            <Description Description1="21" Description2="22"/>
        </Descriptions>
        <Date DateType="Date of Birth">
            <DateValue Year="1992" />
        </Date>
    </Person>
</Records>
我添加的嵌套循环是

<xsl:for-each select="../../../RoleDetail/Roles/OccTitle">
    <xsl:variable name="roleval" select="."/>
...
</xsl:for-each>
这一个用于数据,这个节点可能在XML数据文件中,也可能不在XML数据文件中,如果这个节点不是在XML中,只需将其保留为空,否则它也应该是循环

<RoleDetail>
<Roles RoleType="Primary">
<OccTitle SinceDay="17" SinceMonth="Nov" SinceYear="2009" OccCat="6">Thai</OccTitle>
</Roles>
</RoleDetail>
现在,问题是最后两行没有显示,Col occtile,SinceDay和SinceMonth也为空 非常感谢您这样做:

<xsl:for-each select="../../../RoleDetail/Roles/OccTitle">
    <xsl:variable name="roleval" select="."/>
致:

首先,您应该将变量命名为$occTitle,以使其更清晰,从而避免此错误

此节点可能位于XML数据文件中,也可能不位于XML数据文件中


恐怕这是一个完全不同的问题。这里有一种多维矩阵-如果其中一个维度为0,那么整个矩阵将为空。

ohh,对了,XPATH问题。。我应该多读一点。a多维矩阵中有没有办法输入1或一些默认值?我试图在WHEN中添加一个元素,但仍然失败。大约35个可选元素:@user3724711-Ouch。这并不简单。我建议你把这个作为一个单独的问题发布。
<RoleDetail>
<Roles RoleType="Primary">
<OccTitle SinceDay="17" SinceMonth="Nov" SinceYear="2009" OccCat="6">Thai</OccTitle>
</Roles>
</RoleDetail>
<xsl:for-each select="../../../RoleDetail/Roles/OccTitle">
    <xsl:variable name="roleval" select="."/>
<td>
    <xsl:value-of select="$roleval/OccTitle"/>
</td>
<td>
    <xsl:value-of select="$roleval/OccTitle/@SinceDay"/>
</td>
<td>
    <xsl:value-of select="$roleval/OccTitle/@SinceMonth"/>
</td>
<td>
    <xsl:value-of select="$roleval"/>
</td>
<td>
    <xsl:value-of select="$roleval/@SinceDay"/>
</td>
<td>
    <xsl:value-of select="$roleval/@SinceMonth"/>
</td>