2016-08-01 37 views
-1

我的XML貌似这个我想他的名字是data.xml中如何检查复选框如果XML值是肯定的,如果没有选中比

<?xml version="1.0" standalone="yes"?> 
<CATALOG> 
    <orderByTitleDesc /> 
    <orderByTitleDesc /> 
    <orderByTitleDesc /> 
    <orderByTitleDesc /> 
    <orderByTitleDesc /> 
    <orderByTitleDesc /> 
    <orderByTitleDesc /> 
    <orderByTitleDesc /> 
    <CD /> 
    <CD> 
    <ID>1</ID> 
    <LocationID>wqe</LocationID> 
    <ChangeValueFor>qwe</ChangeValueFor> 
    <Banner>wew</Banner> 
    <DataEntry>Yes</DataEntry> 
    <LocalView>No</LocalView> 
    <Export>Yes</Export> 
    <View>qwe</View> 
    <ActiveView>wqe</ActiveView> 
    <HelpFile>qwe`qw</HelpFile> 
    <Location01>qwe</Location01> 
    <Location02>eq</Location02> 
    <Location03>we</Location03> 
    <Location04>wqew</Location04> 
    <Location05>qws</Location05> 
    <Location06>sds</Location06> 
    <Location07>wde</Location07> 
    <Location08>sd</Location08> 
    <Location09>sad</Location09> 
    <Server>31 March 2014 testing with font</Server> 
    <Server2>171.21.102.11</Server2> 
    <Server3>171.21.102.11</Server3> 
    <CodeBase>CodeBase2</CodeBase> 
    <CodeBase2>ZaidiTest</CodeBase2> 
    <CodeBase3>test222</CodeBase3> 
    <ClassiscID>ClassID312131313</ClassiscID> 
    <ClassiscID2>31 amrch testing for font</ClassiscID2> 
    <ClassiscID3>ClassID2</ClassiscID3> 
    <Theme>VashnoDevi</Theme> 
    <Theme2>class</Theme2> 
    <Theme3>class</Theme3> 
    <Theme4>Theme2</Theme4> 
    <Theme5>Ser</Theme5> 
    <Theme6>Themes1test</Theme6> 
    </CD> 

<DataEntry><LocalView><Export>是肯定比我的支票盒子是Y检查,并保持否比未选中(原样)。

我的XSLT文件如下: 我只是想只在数据录入只添加一个复选框,请告诉我,我做的错误

Myxslt文件如下:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> 
    <xsl:template match="/"> 
    <html> 
     <body style="font-family:Helvetica Neue"> 
     <!--<Div id="ListingScreen" style="display:Yes;">--> 
     <Div id="ListingScreen"> 
      <table border="1" width="1024px" > 
      <tr bgcolor="blue"> 
       <FONT 
      style="BACKGROUND-COLOR: #0000ff"> 
       <FONT color="white"> 
        <STRONG> 
        Maintenance of Parameters for Cube Access 
        </STRONG> 
       </FONT> 
       </FONT> 
      </tr> 
      <tr> 
       <td align="right" colspan="8"> 
       <img src="http://localhost:51242/Images/AFKLLogo.png" alt="Smiley face" width="210"></img> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="8"> 
       <h1>WPTesting - Cube List Web Part</h1> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="8" align="center"> 
       <input type="Button" id="btnAddMasterData" value="Add Master Data" onclick="javascript:AddMasterData()"/> 
       <input type="Button" id="btnAdd" value=" Add " onclick="javascript:location.href='AddMaster.aspx'"/> 
       </td> 
      </tr> 
      <tr> 
       <th id="location">Location ID</th> 
       <th>Data Entry</th> 
       <th>Export</th> 
       <th>Local View</th> 
       <th>Banner</th> 
       <th>Server</th> 
       <th>View</th> 
       <th>Locl</th> 
      </tr> 

      <xsl:choose> 
       <xsl:when test="CATALOG/orderByTitle"> 
       <xsl:for-each select="CATALOG/CD" order-by="+ TITLE"> 
        <tr> 
        <td onclick="javascript:FillEditScreen(this.innerText);"> 
         <a href="javascript:void(0);"> 
         <p style="display:none;"> 
          <xsl:value-of select="ID"/> 
         </p> 
         <xsl:value-of select="LocationID"/>          
         </a> 
         <input type="checkbox" id="chkdataentry" /> 
         <xsl:value-of select='DataEntry'/> 
        </td> 
        <td> 
         <input type="checkbox" id="chkLocalView" /> 
         <xsl:value-of select='LocalView'/> 
        </td> 
        <td> 
         <input type="checkbox" id="chkExport"/> 
         <xsl:value-of select='Export'/> 
        </td> 
        <td> 
         <xsl:value-of select="Banner"/> 
        </td> 
        <td> 
         <xsl:value-of select="Server"/> 
        </td> 
        <td> 
         <xsl:value-of select="View"/> 
        </td> 
        <td> 
         <xsl:value-of select="Location01"/> 
        </td> 
        </tr> 
       </xsl:for-each> 
       </xsl:when> 
       <xsl:when test="CATALOG/orderByTitleDesc"> 
       <xsl:for-each select="CATALOG/CD" order-by="- TITLE"> 
        <tr> 
        <td onclick="javascript:FillEditScreen(this.innerText);"> 
         <a href="javascript:void(0);"> 
         <p style="display:none;"> 
          <xsl:value-of select="ID"/> 
         </p> 
         <xsl:value-of select="LocationID"/> 

         </a> 
        </td> 

        <input type="checkbox" name="DataEntry" value="Milk"> 
         <xsl:if test="CATALOG/CD='Yes'"> 
         <xsl:attribute name="checked">checked</xsl:attribute> 
         </xsl:if> 
        </input> 
        <!--<td> 
         <input type="checkbox" checked="true" id="chk" value="Milk"/> 
        </td>--> 
        <td> 
         <input type="checkbox" checked="true" name="Export" value="export"/> 
        </td> 
        <td> 
         <input type="checkbox" checked="true" name="LocalView" value="export"/> 
        </td> 
        <td> 
         <xsl:value-of select="Banner"/> 
        </td> 
        <td> 
         <xsl:value-of select="Server"/> 
        </td> 
        <td> 
         <xsl:value-of select="View"/> 
        </td> 
        <td> 
         <xsl:value-of select="Location01"/> 
        </td> 
        </tr> 
       </xsl:for-each> 
       </xsl:when> 
       <xsl:when test="CATALOG/orderByArtist"> 
       <xsl:for-each select="CATALOG/CD" order-by="+ ARTIST"> 
        <tr bgcolor="blue"> 
        <td> 
         <input type="Button" id="btnArtist" value="Impala"/> 
        </td> 
        <td> 
         <input type="checkbox" id="chk" value="Milk"/> 
        </td> 
        <td> 
         <input type="checkbox" name="Export" value="export"/> 
        </td> 
        <td> 
         <input type="checkbox" checked="true" name="LocalView" value="export"/> 
        </td> 
        <td> 
         <xsl:value-of select="Banner"/> 
        </td> 
        <td> 
         <xsl:value-of select="Server"/> 
        </td> 
        <td> 
         <xsl:value-of select="View"/> 
        </td> 
        <td> 
         <xsl:value-of select="Locl"/> 
        </td> 
        </tr> 
       </xsl:for-each> 
       </xsl:when> 
      </xsl:choose> 
      </table> 
     </Div> 
     </body> 
    </html> 
    </xsl:template> 
</xsl:stylesheet> 

的主要代码是这样变薄,但它给我的错误不知道为什么

<input type="checkbox" name="DataEntry" value="Milk"> 
        <xsl:if test="CATALOG/CD='Yes'"> 
        <xsl:attribute name="checked">checked</xsl:attribute> 
        </xsl:if> 
       </input> 

回答

0

你还没有真正说你的错误是什么,或者你出什么EXPE输出克,但我可以看到一些问题。

首先,您的XLST命名空间错误http://www.w3.org/TR/WD-xsl是微软在正式XSLT规范发布之前使用的旧版本。它应该是http://www.w3.org/1999/XSL/Transform。如果您更改了它,则需要对XSLT进行一些更改。相反,这样做的......

<xsl:for-each select="CATALOG/CD" order-by="+ TITLE"> 

你需要这样做,因为order-by没有在正式的定义允许的。

<xsl:for-each select="CATALOG/CD" > 
    <xsl:sort select="TITLE" order="descending" /> 

其次,如果你目前的xsl:if检查你检查CATALOG/CD='Yes',但你已经定位在CD这样的表达需要相对于这一点。看起来你确实需要检查DataEntry元素,所以你应该在条件中使用它。

<td> 
    <input type="checkbox" name="DataEntry" value="Milk"> 
    <xsl:if test="DataEntry='Yes'"> 
     <xsl:attribute name="checked">checked</xsl:attribute> 
    </xsl:if> 
    </input> 
</td> 

另外请注意,您的XSLT样本中你没有封闭在tdinput标签,这将影响到它是如何在页面上呈现。

最后,尽管它不会导致错误,但您的XSLT中有很多重复的代码。请考虑使用CD元素的模板。

试试这个XSLT作为一个例子

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 

    <xsl:template match="/"> 
    <html> 
     <body style="font-family:Helvetica Neue"> 
     <Div id="ListingScreen"> 
      <table border="1" width="1024px" > 
      <tr> 
       <th id="location">Location ID</th> 
       <th>Data Entry</th> 
       <th>Export</th> 
       <th>Local View</th> 
       <th>Banner</th> 
       <th>Server</th> 
       <th>View</th> 
       <th>Locl</th> 
      </tr> 
      <xsl:choose> 
       <xsl:when test="CATALOG/orderByTitle"> 
       <xsl:apply-templates select="CATALOG/CD"> 
        <xsl:sort select="TITLE" /> 
       </xsl:apply-templates> 
       </xsl:when> 
       <xsl:when test="CATALOG/orderByTitleDesc"> 
       <xsl:apply-templates select="CATALOG/CD"> 
        <xsl:sort select="TITLE" order="descending" /> 
       </xsl:apply-templates> 
       </xsl:when> 
       <xsl:when test="CATALOG/orderByArtist"> 
       <xsl:apply-templates select="CATALOG/CD"> 
        <xsl:sort select="ARTIST" /> 
       </xsl:apply-templates> 
       </xsl:when> 
      </xsl:choose> 
      </table> 
     </Div> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="CD"> 
    <tr> 
     <td onclick="javascript:FillEditScreen(this.innerText);"> 
      <a href="javascript:void(0);"> 
      <p style="display:none;"><xsl:value-of select="ID"/></p> 
      <xsl:value-of select="LocationID"/> 
      </a> 
     </td> 
     <td> 
      <input type="checkbox" name="DataEntry" value="dataentry"> 
       <xsl:if test="DataEntry='Yes'"> 
       <xsl:attribute name="checked">checked</xsl:attribute> 
       </xsl:if> 
      </input> 
     </td> 
     <td> 
      <input type="checkbox" name="Export" value="export"> 
       <xsl:if test="Export='Yes'"> 
       <xsl:attribute name="checked">checked</xsl:attribute> 
       </xsl:if> 
      </input> 
     </td> 
     <td> 
      <input type="checkbox" name="LocalView" value="localview"> 
       <xsl:if test="LocalView='Yes'"> 
       <xsl:attribute name="checked">checked</xsl:attribute> 
       </xsl:if> 
      </input> 
     </td> 
     <td><xsl:value-of select="Banner"/></td> 
     <td><xsl:value-of select="Server"/></td> 
     <td><xsl:value-of select="View"/></td> 
     <td><xsl:value-of select="Location01"/></td> 
    </tr> 
    </xsl:template> 
</xsl:stylesheet> 
+0

其工作要命添谢谢你一吨... –

相关问题