如何在XSL样式表上使用follow-sibling来仅选择XML文件中的作者?

时间:2011-11-20 16:22:13

标签: xml xslt xpath

我有一个XML文件,显示来自作者的pubblications与一些文章或inproceeding节点。像这样:

<dblp>
<inproceedings key="aaa" mdate="bbb">
<author>author1</author>
<author>author2</author>
<author>author3</author>
<author>author4</author>
<title>Title of pubblications</title>
<pages>12345</pages>
<year>12345</year>
<crossref>sometext</crossref>
<booktitle>sometext</booktitle>
<url>sometext</url>
<ee>sometext</ee>
</inproceedings>

<article key="aaa" mdate="bbb">
<author>author1</author>
<author>author2</author>
<title>Title of pubblications</title>
<pages>12345</pages>
<year>12345</year>
<crossref>sometext</crossref>
<booktitle>sometext</booktitle>
<url>sometext</url>
<ee>sometext</ee>
</article>

</dblp>

我必须创建一个XSL样式表,以便在.dot文件中转换此文件,该文件仅显示与所有pubblications中作者的协作。像这样:

author1--author2;
author1--author3;
author1--author4;
author2--author3;
author2--author4;
author3--author4;

这是第一个pubblication,第二个是:

author1--author2;

我必须写作者的所有连接,没有重复。我怎样才能做到这一点? 我写了一些东西来显示所有的连接,但我必须删除重复。我可以使用以下兄弟来解决吗?

<xsl:variable name="papers" select="dblp/*"/>
        <xsl:for-each select="$papers">
            <xsl:variable name="autori" select="author"/>
            <xsl:variable name="autori2" select="author"/>
            <xsl:for-each select="$autori">
                <xsl:variable name="i" select="node()"/>
                    <xsl:for-each select="$autori2">
                        <xsl:if test=".!=$i">
                            <xsl:value-of select="$i"/><xsl:text>--</xsl:text><xsl:value-of select="."/><xsl:text>;</xsl:text>
                        </xsl:if>
                    </xsl:for-each><xsl:text>&#xa;</xsl:text>
            </xsl:for-each>
        </xsl:for-each>

感谢您的回答!

1 个答案:

答案 0 :(得分:1)

<xsl:for-each select="author[position() != last()]">
  <xsl:variable name="a1" select="."/>
  <xsl:for-each select="following-sibling::author">
    <xsl:value-of select="concat($a1, '--', ., ';&#10;')"/>
  </xsl:for-each>
</xsl:for-each>