xslt-for each-逐行
我对XSLT pasing for each有一个问题xslt-for each-逐行,xslt,foreach,Xslt,Foreach,我对XSLT pasing for each有一个问题 <publication> <publicationId>1234</publicationId> <title>some title</title> <type>some type</type> <authors> <author>author 1</author> <author>author 2</
<publication>
<publicationId>1234</publicationId>
<title>some title</title>
<type>some type</type>
<authors>
<author>author 1</author>
<author>author 2</author>
</authors>
<journal>true</journal>
</publication>
<xsl:template match="/">
<xsl:for-each select=publication">
<xsl:for-each select="authors">
<xsl:value-of select="."/>,
</xsl:for-each>
</xsl:for-each>
1234
一些头衔
某种类型
作者1
作者2
真的
而不是这样做
<xsl:for-each select="authors">
你应该这样做
<xsl:for-each select="authors/author">
这是因为只有一个“authors”节点,但有很多“author”节点,这就是您要迭代的“author”节点
事实上,您可以将两个循环合并为一个,如下所示:
<xsl:for-each select="publication/authors/author">
我会做必要的事。另外,在添加“,”时,最好使用
标记。为什么使用
标记更好?据我所知,将以两行显示输出。@Kilazur,因为这样您就不必担心缩进样式表。我的XML文件有很多。。标记,我希望每个都有以下输出:第一次发布:author1,author2第二次发布:author1,author2,author3
<xsl:for-each select="publication/authors/author">