0
你好,我嘗試使用XSLT如何獲得一個變量在內部for循環XSL
<?xml version="1.0" encoding="utf-8"?>
<posts>
<row Id="1" PostTypeId="1" AcceptedAnswerId="13" CreationDate="2010-09-13T19:16:26.763" Score="45" ViewCount="8799" Body="<p>This is a common question by those who have just rooted their phones. What apps, ROMs, benefits, etc. do I get from rooting? What should I be doing now?</p>
" OwnerUserId="10" LastEditorUserId="267" LastEditorDisplayName="" LastEditDate="2011-01-25T16:00:21.373" LastActivityDate="2011-08-02T14:44:12.740" CommunityOwnedDate="2011-01-25T08:44:10.820" Title="I've rooted my phone. Now what?" Tags="<rooting>" AnswerCount="8" CommentCount="5" FavoriteCount="31" />
<row Id="2" PostTypeId="1" AcceptedAnswerId="4" CreationDate="2010-09-13T19:17:17.917" Score="10" ViewCount="619" Body="<p>I have a Google Nexus One with Android 2.2. I didn't like the default SMS-application so I installed Handcent-SMS. Now when I get an SMS, I get notified twice. How can I fix this?</p>
" OwnerUserId="7" LastEditorUserId="7" LastEditorDisplayName="" LastEditDate="2010-09-13T19:25:52.433" LastActivityDate="2010-09-13T19:25:52.433" Title="I installed another SMS application, now I get notified twice" Tags="<2.2-froyo><sms><handcent-sms><applications><notifications>" AnswerCount="3" FavoriteCount="2" />
<row Id="4" PostTypeId="2" ParentId="2" CreationDate="2010-09-13T19:19:23.200" Score="16" ViewCount="" Body="<p>You can turn off notification in your stock Messaging application by going into the settings dialog (Menu button -> Settings) and unchecking Notifications</p>
" OwnerUserId="21" LastActivityDate="2010-09-13T19:19:23.200" CommentCount="1" />
<row Id="5" PostTypeId="1" CreationDate="2010-09-13T19:19:35.360" Score="5" ViewCount="234" Body="<p>I have a Motorola DROID v1 that is running Froyo (2.2). I've noticed that if my device sleeps for a while, when I wake it up it will not attempt to connect to the wireless AP in my home. When I go to the wireless settings section, I see a note next to the AP entry that says 'disabled'. If I click the entry and select 'connect', it connects right away. It will remain connected until the next longish sleep, when it is again marked as disabled.</p>

<p>Is there any way to prevent this AP entry from being marked as disabled?</p>
" OwnerUserId="9" LastActivityDate="2011-09-05T03:43:01.573" Title="Moto Droid v1 disabling primary Wireless AP" Tags="<2.2-froyo>" AnswerCount="1" CommentCount="7" FavoriteCount="1" />
<row Id="6" PostTypeId="1" CreationDate="2010-09-13T19:20:47.643" Score="2" ViewCount="67" Body="<p>Google recently intoduced a new mechanism for developers to protect their applications from piracy - the License Verification Library. I've been looking at incorporating this into my apps (in fact I have it working) but I'm concerned that it will adversely affect the user experience.</p>

<p>Has anybody had problems using apps that incorporate the licensing check? Does it cause problems when you don't have Internet connectivity in order to do the validation? Are there any other annoyances from an end-user perspective?</p>
" OwnerUserId="19" LastActivityDate="2010-10-13T22:41:58.303" Title="Experiences with Google's new licensing service for apps?" Tags="<market>" AnswerCount="1" />
<row Id="7" PostTypeId="2" ParentId="2" CreationDate="2010-09-13T19:20:52.027" Score="2" ViewCount="" Body="<p>Open the default messaging application, click the menu button and then Settings. Scroll down and disable <strong>Notifications</strong>.</p>
" OwnerUserId="27" LastActivityDate="2010-09-13T19:20:52.027" />
我使用它來解析XML
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="posts/row">
<xsl:if test="@PostTypeId = 2">
<xsl:variable name="parent" select="@ParentId"/>
<xsl:for-each select="/posts/row">
<xsl:if test="@PostTypeId = 1">
<xsl:variable name="patentVariable" select="$parent"/>
<xsl:if test="@ParentId = $patentVariable">
<field name ="$parentid"><xsl:value-of select="@Title" /></field>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我不能解析XML在for循環中打印父id可以告訴我如何做到這一點?
預期輸出
<field name="1">I've rooted my phone. Now what?</field>
您好!在這種情況下是否可以顯示您的預期產出?謝謝! –
有兩種類型,一種是PostTypeId = 1,它具有title屬性,另一種是PostTypeId = 2,它具有指向PostType = 1的parentId,我需要獲得postTypeId = 2的標題 – Kathick