检查xslt案例?

时间:2013-09-25 12:02:29

标签: xslt

我有一个xslt

<category numberofproducts="0">
  <id>Main</id>
  <url>/products/Main</url>
  <name>Main</name>
  <texts>
    <text language="standard">
      <name>Name</name>
      <longdescription></longdescription>
      <shortdescription></shortdescription>
      <htmltitle></htmltitle>
      <metadescription></metadescription>
      <metakeywords></metakeywords>
    </text>
  </texts>
  <name>Kopipapir</name>
  <longdescription></longdescription>
  <shortdescription></shortdescription>
  <htmltitle></htmltitle>
  <metadescription></metadescription>
  <metakeywords></metakeywords>
  <category numberofproducts="47">
    <id>Name1</id>
    <url>/products/Name1</url>
    <name>Name1, New</name>
    <texts>
      <text language="standard">
        <name>New, Nmae</name>
        <longdescription></longdescription>
        <shortdescription></shortdescription>
        <htmltitle></htmltitle>
        <metadescription></metadescription>
        <metakeywords></metakeywords>
      </text>
    </texts>
   </category>
  <category numberofproducts="23">
    <id>Name2</id>
    <url>/products/Name2</url>
    <name>Name2, hvd</name>
    <texts>
      <text language="standard">
        <name>Name2, hvd</name>
        <longdescription></longdescription>
        <shortdescription></shortdescription>
        <htmltitle></htmltitle>
        <metadescription></metadescription>
        <metakeywords></metakeywords>
      </text>
    </texts>
   </category>

我需要检查类别中是否有类别

我尝试了类似的事情。

<xsl:choose>
      <xsl:when test="$ccat/category//category != '' ">

          <xsl:text >Category</xsl:text>

      </xsl:when>
      <xsl:otherwise>
        <xsl:text>Listing</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

有人帮忙吗?

1 个答案:

答案 0 :(得分:1)

我在下面的回答中,假设您希望检查类别根目录

下是否存在任何类别子项
<xsl:if test="boolean(/category//category)='true'">
    <xsl:text>Category</xsl:text>
</xsl:if>