开发者

C# .xsl view from xml -- only outputs the first element

I'm learning on the fly, and I have commented C# code with /// that generates xml after:

csc Class1.cs /out:Class1Docs /rescurse:*.cs /doc:Class1Doc开发者_高级运维.xml

My xsl file (the relevant part) is like so:

<xsl:for-each select="doc">
            <br>
              <xsl:value-of select="members/member"/>
            </br>
            <br>
              <xsl:value-of select="summary"/>
            </br>
          </xsl:for-each>
      </body>
    </html>
</xsl:template>

The problem is that I need to output the member, summary, params, and return value. I only get the 'member/member' returned: Class1 Class

How do i select the xsl:value of for each tag ?


My xsl file (the relevant part) is like so:

<xsl:for-each select="doc">
 <br>               
  <xsl:value-of select="members/member"/
 </br>             
 <br>               
  <xsl:value-of select="summary"/>             
 </br>           
</xsl:for-each>       
</body>     
</html> 
</xsl:template>

This is badly malformed XML!

Let's think that the relevant, well-formed portion is:

  <xsl:for-each select="doc">
    <br>
     <xsl:value-of select="members/member"/>
    </br>
    <br>
      <xsl:value-of select="summary"/>
    </br>
  </xsl:for-each>

There are many problems with this code:

  1. AFAIK the (x)HTML element br should have no content. Maybe you wanted:



  2. <xsl:value-of select="members/member"/>

The <xsl:value-of> instruction creates a text node that contains the string value of the first node only, that is specified in the XPath expression in the select attribute.

Probably you wanted:

<xsl:copy-of select="members/member/text()"/>

.3. Specifying all literal result elements and using <xsl:for-each> within a single template is not a good XSLT programming practice. It is recommended to use more templates and correspondingly, <xsl:apply-templates> instead of <xsl:for-each>.


I can't really post the whole XML example because it's internal info

Then it's easy enough to provide an example that exhibits all the necessary properties of the real data, surely? You can't expect people to help you with one hand tied behind their backs.

Like other responders, I'm guessing, but my guess is that you failed to realise that in XSLT 1.0, the xsl:value-of instruction only outputs the string value of the first node in the sequence. If for some reason you can't move to XSLT 2.0, you need to put the xsl:value-of inside an xsl:for-each or xsl:apply-templates loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜