0

I have a large xml file with several nodes slide and the below is a part of my large xml.

<slide add_info="e" name="slide31.xml" nav_lvl_1="Contact" nav_lvl_2="Company" >
    --------something----------
</slide>
<slide add_info="a" name="slide32.xml" nav_lvl_1="References" nav_lvl_2="Company">
    -----something----
</slide>
<slide add_info="b" name="slide33.xml" nav_lvl_1="References" nav_lvl_2="Company" >
    ------something--------
</slide>
<slide add_info="c" name="slide34.xml" nav_lvl_1="References" nav_lvl_2="Company" >
    --------something----------
</slide>
<slide add_info="d" name="slide34.xml" nav_lvl_1="Contact" nav_lvl_2="Company" >
    --------something----------
</slide>

Here i need to group only the slide node which has attribute References and Company and get the all the add_info attribute values of those nodes.For example expected output:

a b c

Currently I am doing :

<xsl:choose>
    <xsl:when test="@nav_lvl_1='References'">
        <xsl:if test="@nav_lvl_2='Company'">
        <xsl:for-each select="//@add_info">
            <xsl:value-of select="."/>
        </xsl:for-each>
        </xsl:if>
    </xsl:when>
 </xsl:choose>

But this gives me all the text value of add_info attribute in the whole document.For example: it gives me:

e a b c d

But I need the output only as a b c How could i change the above xslt code to achieve that.. Any sugggestions..I am stuck here :(

4

1 回答 1

1

您说“组”,但分组特别是要创建具有相同属性的多个组。

要仅选择一组具有特定属性的构造,只需在单个 XPath 地址中对它们进行寻址:

<xsl:for-each select="//slide[@nav_lvl_1='References' and @nav_lvl_2='Company'">
   <xsl:value-of select="@add_info"/>
</xsl:for-each>

...尽管我会放弃//slide并使用地址而不是//到达所有幻灯片的父级,然后将幻灯片作为子级来寻址。

于 2013-07-10T22:02:44.063 回答