0

鉴于此源 XML:

<Objects>
    <Object>
        <Relations>
            <Relation>
                <Placements>
                    <Placement>
                        <Page>6</Page>
                        <Element>body</Element>
                        <FrameOrder>3</FrameOrder>
                        <PageSequence>2</PageSequence>
                        <PageNumber>6</PageNumber>
                    </Placement>
                    <Placement>
                        <Page>1</Page>
                        <Element>body</Element>
                        <FrameOrder>0</FrameOrder>
                        <PageSequence>1</PageSequence>
                        <PageNumber>1</PageNumber>
                    </Placement>
                    <Placement>
                        <Page>6</Page>
                        <Element>body</Element>
                        <FrameOrder>4</FrameOrder>
                        <PageSequence>2</PageSequence>
                        <PageNumber>6</PageNumber>
                    </Placement>
                    <Placement>
                        <Page>1</Page>
                        <Element>head</Element>
                        <FrameOrder>0</FrameOrder>
                        <PageSequence>1</PageSequence>
                        <PageNumber>1</PageNumber>
                    </Placement>
                    <Placement>
                        <Page>1</Page>
                        <Element>body</Element>
                        <FrameOrder>2</FrameOrder>
                        <PageSequence>1</PageSequence>
                        <PageNumber>1</PageNumber>
                    </Placement>
                    <Placement>
                        <Page>1</Page>
                        <Element>body</Element>
                        <FrameOrder>1</FrameOrder>
                        <PageSequence>1</PageSequence>
                        <PageNumber>1</PageNumber>
                    </Placement>
                </Placements>
            </Relation>
        </Relations>
    </Object>
</Objects>

我正在尝试按Page顺序获取元素所在的不同Element元素body

<Pages>
    <Page>1</Page>
    <Page>6</Page>
</Pages>

我似乎得到的最远距离是使用以下 XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/> 
<xsl:template match="/">
<xsl:for-each select="Objects/Object/Relations/Relation/Placements/Placement[Element='body']">
<xsl:sort select="FrameOrder"/>
    <Page><xsl:value-of select="Page"/></Page>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

这给了我:

<Pages>
    <Page>1</Page>
    <Page>1</Page>
    <Page>1</Page>
    <Page>6</Page>
    <Page>6</Page>
</Pages>

我如何获得此时的不同值Page

提前致谢!

4

1 回答 1

1
<xsl:key name="kPage" match="Placement/Page" use="number(.)" />

<xsl:template match="/">
  <Pages>
    <xsl:for-each select="
      //Page[
        generate-id() = generate-id(key('kPage', number(.))[1])
      ]
    ">
      <xsl:sort select="." data-type="number" />
      <xsl:copy-of select="." />
    </xsl:for-each>
  </Pages>
</xsl:template>
于 2012-10-10T07:32:00.593 回答