簡體   English   中英

如何在XSL樣式表上使用跟隨同級來僅選擇XML文件中的作者?

[英]How can i use following-sibling on a XSL stylesheet to select only the authors in a XML file?

我有一個XML文件,其中顯示了作者的文章和相關節點的出版物。 像這樣:

<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文件,該文件僅顯示與所有出版物的作者的協作。 像這樣:

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

這是第一次發布,第二次發布是:

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>

感謝您的回答!

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM