0

I am trying to achieve the following output: that is the lhs column shows only heading once.. and the records populate to column two.

PCP                 Jones, Mary
Care Manager:       abc1 (type1)
                    abc2 (type2)

My xml is:

<careTeames>
<careteame><PCP>JONES,MARY</PCP><type>Ped - Under 5</type>
<caremanagers>
    <caremanager>
        <name>Willis,Sam</name>
        <type>Internal Medicine</type>
    </caremanager>
    <caremanager>
        <name>Willis,Sam-2</name>
        <type>Internal Medicine-2</type>
    </caremanager>
</caremanagers>
</careteame>
</careTeames>

myxslt is:

<table width="100%" cellpadding="2" cellspacing="5">
        <tr>
            <td align="center" width="30%" class="sectionHeader">Care team </td>
        </tr>
        <tr>
            <td align="left" class="sectionBody" valign="top">
                <table class="table1" width="100%" cellpadding="2" cellspacing="5" border="0" >
                <xsl:for-each select="//return/careTeames/careteame">
                    <tr><td>PCP</td><td><xsl:value-of select="PCP"/> (<xsl:value-of select="type"/>) </td></tr><hr/>
                       <xsl:for-each select="caremanagers/caremanager">
                        <tr><td>Care Manager:</td><td><xsl:value-of select="name"/> ( <xsl:value-of select="type"/> )</td></tr>
                        </xsl:for-each> 
                        <hr/>


               </xsl:for-each>

                </table>
            </td>

        </tr>
    </table>

This code prints:

   | care manager| abc1 (type1) |
   | care manager| abc2 (type2) |

Any suggestions??

I just want it to be :

| care manager | abc1(type1)  |
|              |  abc2(type2) |
4

1 回答 1

0

The simplest approach would be to put a position() check inside the inner for-each

<xsl:for-each select="caremanagers/caremanager">
  <tr>
    <td>
      <xsl:choose>
        <xsl:when test="position() = 1">Care Manager:</xsl:when>
        <xsl:otherwise>&#160;</xsl:otherwise>
      </xsl:choose>
    </td>
    <td><xsl:value-of select="name"/> ( <xsl:value-of select="type"/> )</td>
  </tr>
</xsl:for-each>

(&#160; is a no-break space, you can express the same character as &nbsp; in HTML but you can't use that entity reference directly in an XML document unless it references an XHTML DTD).

于 2013-09-23T16:52:03.913 回答