I need help with XSL & ASP.NET questions
I have a page that calls a webservice to get data. The screen wires up correctly and I am able to display the data I expect. Now I need to write another inner loop inside a for-each in the xsl but I need to pass a parameter to sort the parent dataset and just get a subset to display in the child view. Here is my block of code thus far:
Here is the XML
<xs:element name="ExchangeWantedItemsMeToodUsers">
<xs:complexType>
- <xs:sequence>
<xs:element name="ExchangeWantedId" type="xs:int" minOccurs="0" />
<xs:element name="ExchangeWantedName" type="xs:string" minOccurs="0" />
<xs:element name="MeTooer" type="xs:string" minOccurs="0" />
<xs:element name="MeTooerBankName" type="xs:string" minOccurs="0" />
<xs:element name="DateFulfilled" type="xs:string" minOccurs="0" />
<xs:element name="DateFulfilledUnformated" type="xs:dateTime" minOccurs="0" />
<xs:element name="UserID" type="xs:int" minOccurs="0" />
<xs:element name="FullName" type="xs:string" minOccurs="0" />
<xs:element name="PostedBankName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="ExchangeWantedItemsMeToodUsers1">
- <xs:complexType>
- <xs:sequence>
<xs:element name="ExchangeWantedID" type="xs:int" minOccurs="0" />
<xs:element name="DisplayName" type="xs:string" minOccurs="0" />
<xs:element name="FullName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
Here is the xsl
<xsl:for-each select="/root/ExchangeWantedItemsMeToodUsers">
<tr>
<xsl:call-template name="AlternateRowColor" />
<td><xsl:value-of select="ExchangeWantedName" /></td>
<td>
<xsl:for-each select="/root/ExchangeWantedItemsMeToodUsers">
<xsl:value-of select="MeTooer" /> - <xsl:value-of
select="MeTooerBankName" />
</xsl:for-each>
</td>
<td><xsl:value-of select="FullName" /> - <xsl:value-of
select="PostedBankName" /></td>
<td><xsl:value-of select="DateFulfilled" /></td>
</tr>
</xsl:for-e开发者_如何学Goach>
I made a few assumptions here because your question is too high level. I hope I'm not too far off the mark.
I believe that you are looking for something along the line of the following snippet
<xsl:for-each select="/root/ExchangeWantedItemsMeToodUsers[@FullName='xxxxx]">
<xsl:sort select="MeTooer" data-type="text"/>
<xsl:value-of select="MeTooer" /> - <xsl:value-of select="MeTooerBankName" />
</xsl:for-each>
It is highly likely you actually do not need an inner loop for the filtering and the sorting.
You can tighten your filtering conditions by extending the XPath expression already included in your loop directive (for instance, here I took the hypothesis that you already knew the value of the full name you were interested in) - what you call your parameter. Since your question leaves that criteria open I picked up the FullName attribute. Tell us more about this additional filtering conditions. If there is one.
As for the sorting, there is a dedicated XSLT directive made precisely for this situation. It is applied to the node set resulting from the parent
for-each
selection criteria. Again I made an hypothesis here and picked up the first displayed attribute as sorting criteria. Let us know what you really want here again.
精彩评论