xml xslt - 特定数据显示

时间:2013-09-23 16:17:34

标签: xml xslt

我正在尝试实现以下输出:即lhs列仅显示标题一次..并且记录填充到第二列。

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

我的xml是:

<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是:

<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>

此代码打印:

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

有什么建议吗?

我只想要它:

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

1 个答案:

答案 0 :(得分:0)

最简单的方法是在position()内部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;

&nbsp;是一个不间断的空格,您可以在HTML中表达与{{1}}相同的字符,但除非它引用XHTML DTD,否则不能直接在XML文档中使用该实体引用)。