【发布时间】:2014-01-21 04:58:22
【问题描述】:
我对 xslt 比较陌生,我需要根据使用当前帖子的 pid 从哪个帖子中选择 cmets 元素
我遇到问题的 XSLT 部分
<xsl:for-each select="posts/post">
<div class="post">
<h3><xsl:value-of select="ptitle"/></h3>
<span><xsl:value-of select="ptext"/></span>
<xsl:variable name="pid" select="@pid" />
<!-- Here i need to select the comment according to the pid -->
</div>
<br />
</xsl:for-each>
XML 代码
<posts>
<post pid="p2">
<ptitle>APPLICATIONS OF THE FUTURE</ptitle>
<pfeatureimage>aig.jpg</pfeatureimage>
<ptext xml:lang="en">just text </ptext>
<pdate>25062013</pdate>
<pimg>future.jpg</pimg>
<pimg>future.jpg</pimg>
<pimg>future.jpg</pimg>
<pauthorid>a3</pauthorid>
</post>
</posts>
<comments>
<comment cid="c1">
<pid>p2</pid>
<uid>u2</uid>
<ctext>other t</ctext>
<likes>5</likes>
<dislikes>1</dislikes>
</comment>
<comment cid="c2">
<pid>p3</pid>
<uid>u2</uid>
<ctext>bogsg</ctext>
<likes>5</likes>
<dislikes>1</dislikes>
</comment>
</comments>
【问题讨论】:
-
您需要的 XPath 表达式是这样的:
//comments/comment[pid=current()/@pid]。