2013-05-03 186 views
2

您可以請幫助以下xslt。在下面的xml中,如果ul節點具有data-type =「taxonomy」不包含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> 

預期輸出。與屬性數據類型值等於「分類法」的後代UL

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

匹配(並且忽略)UL和具有不後代UL:

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

回答

1

嘗試此。

+0

嗨Hr_117。這是完美的工作。我很感激同樣的事情 – gullamahi 2013-05-03 16:22:56