2

次の xslt について教えてください。次の xml で、data-type ="taxonomy" を持つ ul ノードに ul 子ノードが含まれていない場合、その ul ノードの親は、この場合、属性 id="a12345600" を持つ ul ノードを出力から除外する必要があります。

<div class="css-treeview">                
 <ul id="a12345dem" data-id="a12345dem" data-type="taxonomy">  ## this node has to be omitted in the output##
    <li>
      <input type="checkbox" />
      <label>Sample Publications</label>
      <ul id="dc0d58dc" data-id="dc0d58dc" data-type="taxonomy"> ## here ul node with attribute has  data-type="taxonomy" no child ul node##
        <li>
          <input type="checkbox" />
          <label>Word</label>
        </li>
      </ul>    
    </li>
  </ul>
  <ul id="bcba11a9" data-id="bcba11a9" data-type="taxonomy">
    <li>
      <input type="checkbox" />
      <label>AfDB</label>
      <ul id="9cae7833" data-id="9cae7833" data-type="taxonomy">
        <li>
          <input type="checkbox" />
          <label>Tunis</label>
          <ul id="Content is the King sai ram" data-id="f02a0f2a" data-taxonomy="9cae7833">
            <li>
              <input type="checkbox" id="item-0" />
              <label for="item-0">
                <a class="lnkPub" data-pid="f02a0f2a" onclick="doContentLoad(this,'1_Front_Matter/publication.htm', '1', '1')" title="Content is the King sai ram">Content is the King sai ram</a>
              </label>          
            </li>
          </ul>        
        </li>
      </ul>    
      <ul id="Eine ganz normale Projektentwicklung for Demo" data-id="b1acb679" data-taxonomy="bcba11a9">
        <li>
          <input type="checkbox" id="item-0" />
          <label for="item-0">
            <a class="lnkPub" data-pid="b1acb679" onclick="doContentLoad(this,'1_Front_Matter/publication.htm', '1', '1')" title="Eine ganz normale Projektentwicklung for Demo">Eine ganz normale Projektentwicklung for Demo</a>
          </label>         
        </li>
      </ul>

    </li>
  </ul>
  <ul id="c8149f59" data-id="c8149f59" data-type="taxonomy">
    <li>
      <input type="checkbox" />
      <label>Siemens</label>
      <ul id="SCORM SCORM" data-id="79618046" data-taxonomy="bcba11a9">
        <li>
          <input type="checkbox" id="item-0" />
          <label for="item-0">
            <a class="lnkPub" data-pid="79618046" onclick="doContentLoad(this,'1_Front_Matter/publication.htm', '1', '1')" title="SCORM SCORM">SCORM SCORM</a>
          </label>         
        </li>
      </ul>
    </li>
  </ul>

XSLT

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html></xsl:text>
    <html>
      <head>
        <title />
        <script src="Navigation.js">
        </script>
        <link rel="stylesheet" href="Navigation.css" />
        <link rel="stylesheet" href="treeview.css" />
        <style>nav#MainNav a {padding-top:10px !important; display: block}</style>
      </head>
      <body>
        <header class="navHeader">
          <nav>
            <a href="Taxonomy.htm">Taxonomy</a>
            <a href="Title.htm">Title</a>
            <a href="Date.htm">Date</a>
          </nav>
        </header>
        <nav id="MainNav">
         <div>
           <xsl:apply-templates select="@*" />
           <xsl:apply-templates select="ul">

           </xsl:apply-templates>
           </div>
        </nav>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="*|@*|text()">

    <xsl:copy>
      <xsl:apply-templates select="*|@*|text()" />
    </xsl:copy>

  </xsl:template>

  <xsl:template match="div">
    <xsl:copy>
      <xsl:apply-templates select="ul|@*|text()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="div/ul/li">
    <xsl:copy>
      <xsl:apply-templates select="*|@*|text()">
        <xsl:sort select="@data-title"/>

      </xsl:apply-templates>

    </xsl:copy>
  </xsl:template>
##xslt I used to remove the specific node##
  <xsl:template match="li[../@data-type='taxonomy']/label[not(following-sibling::ul)]">


  </xsl:template>

</xsl:transform>

期待される出力。

 <div class="css-treeview">
  <ul id="bcba11a9" data-id="bcba11a9" data-type="taxonomy">
    <li>
      <input type="checkbox" />
      <label>AfDB</label>
      <ul id="9cae7833" data-id="9cae7833" data-type="taxonomy">
        <li>
          <input type="checkbox" />
          <label>Tunis</label>
          <ul id="Content is the King sai ram" data-id="f02a0f2a" data-taxonomy="9cae7833">
            <li>
              <input type="checkbox" id="item-0" />
              <label for="item-0">
                <a class="lnkPub" data-pid="f02a0f2a" onclick="doContentLoad(this,'1_Front_Matter/publication.htm', '1', '1')" title="Content is the King sai ram">Content is the King sai ram</a>
              </label>          
            </li>
          </ul>        
        </li>
      </ul>    
      <ul id="Eine ganz normale Projektentwicklung for Demo" data-id="b1acb679" data-taxonomy="bcba11a9">
        <li>
          <input type="checkbox" id="item-0" />
          <label for="item-0">
            <a class="lnkPub" data-pid="b1acb679" onclick="doContentLoad(this,'1_Front_Matter/publication.htm', '1', '1')" title="Eine ganz normale Projektentwicklung for Demo">Eine ganz normale Projektentwicklung for Demo</a>
          </label>         
        </li>
      </ul>

    </li>
  </ul>
  <ul id="c8149f59" data-id="c8149f59" data-type="taxonomy">
    <li>
      <input type="checkbox" />
      <label>Siemens</label>
      <ul id="SCORM SCORM" data-id="79618046" data-taxonomy="bcba11a9">
        <li>
          <input type="checkbox" id="item-0" />
          <label for="item-0">
            <a class="lnkPub" data-pid="79618046" onclick="doContentLoad(this,'1_Front_Matter/publication.htm', '1', '1')" title="SCORM SCORM">SCORM SCORM</a>
          </label>         
        </li>
      </ul>
    </li>
  </ul>
</div>
4

1 に答える 1

1

これを試して:

<xsl:template match="ul[descendant::ul[@data-type='taxonomy' and  not(descendant::ul) ] ]"/>

属性データ型の値が「分類法」に等しく、子孫 ul を持たない子孫 ul と ul を照合 (および無視) します。

于 2013-05-03T16:05:46.140 に答える