1
我有以下XML:XSL模板不匹配一切
<function>
<success>
<response code="200" name="Ok">
<content name="yellogUserId" type="long" />
<contents name="functionalAreas" type="Json[]">
<content name="functionalAreaId" type="long" />
<content name="functionalAreaName" type="String" />
<contents name="workPlaces" type="Json[]">
<content name="workPlaceId" type="long" />
<content name="workPlaceName" type="String" />
</contents>
</contents>
</response>
</success>
</function>
我有把XML到HTML文件的.xsl文件。现在的问题是CONTENT和CONTENTS节点。这两个可以无限地嵌套(CONTENT没有孩子,CONTENTS始终有内容作为孩子,但也可以包含更多的内容)。我的XSL是这样的:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" omit-xml-declaration="yes" />
<xsl:template match="contents[content]">
<li>
<xsl:value-of select="@name" /> : <xsl:value-of select="@type" />
<ul>
<xsl:apply-templates select="content" />
</ul>
</li>
</xsl:template>
<xsl:template match="content">
<li><xsl:value-of select="@name" /> : <xsl:value-of select="@type" /></li>
</xsl:template>
<xsl:template match="/">
<div class="jumbotron">
<table class="table table-bordered">
<tr>
<td class="tdleft">Success Response</td>
<td class="tdright">
<xsl:for-each select="function/success/response">
<xsl:value-of select="@code" /> - <xsl:value-of select="@name" />
<xsl:if test="content">
<br/>
Content:
<ul>
<xsl:apply-templates select="content" />
<xsl:apply-templates select="contents" />
</ul>
</xsl:if>
<br/><br/>
</xsl:for-each>
</td>
</tr>
</table>
</div>
</xsl:template>
</xsl:stylesheet>
什么,当我改变它,我得到的是这样的:
yellogUserId : long
functionalAreas : Json[]
functionalAreaId : long
functionalAreaName : String
但我想是这样的:
yellogUserId : long
functionalAreas : Json[]
functionalAreaId : long
functionalAreaName : String
workPlaces : Json[]
workPlaceId : long
workPlaceName : String
的问题是,它只匹配第一层,但不会深入,这是我想要的。 (对不起,如果这听起来有点奇怪,我不知道如何描述它更好)
您的解决方案的工作,非常感谢你! –