从数据库生成的xml [英] xml generating from database

查看:70
本文介绍了从数据库生成的xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用xml生成html。我的数据库给我价值

menuid name parentid IsChecked

1酒店null checked

2度假村1

3 Swiming Pool 2已经检查



i有这个创建xml文件





 <?  xml    版本  =  1.0    encoding   =  utf-8  >  
< span class =code-keyword>< xsl:stylesheet < span class =code-attribute> version = 1.0 xmlns:xsl = http://www.w3.org/1999/XSL/Transform

xmlns:msxsl = urn:schemas-microsoft-com:xslt exclude-result-前缀 = msxsl

>
< xsl:output 方法 = xml 缩进 = 编码 = utf-8 / >

< xsl:template < span class =code-attribute>匹配 = /菜单 >
< ul >


< xsl:call-template name = 菜单列表 / >
< / ul >
< / xsl:template >
<! - 允许重复子节点处理 - >
< xsl:template 名称 = 菜单列表 >
< xsl:apply-templates 选择 = 菜单 / >
< / xsl:模板 >

< xsl:template match = 菜单 >
< li >
< a >
<! - 将菜单子元素转换为< li> < a取代; html标签并在< a>内添加属性标记 - >
< xsl:attribute name = href >
< xsl:value-of 选择 = url / >
< / xsl:属性 >
< xsl:value-of s选举 = 名称 / >
< / a >
< 输入 >
< xsl:attribute name = id >
< ; xsl:value-of select = menuid / >
< / xsl:attribute >
< xsl:attribute name = 类型 >
< xsl:text > 复选框< / xsl:text >
< / xsl:attribute >
< xsl:attr ibute 名称 = class >
< xsl:text > selectCat < / xsl:text >
< / xsl:attribute >
< xsl:attribute name = 选中 >
< xsl:value-of 选择 = IsChecked / >
< / xsl:attribute >

< / input >


<! - 如果有子菜单节点,则调用MenuListing - >
< xsl:if test = c ount(菜单)> 0 >
< ul >
< xsl:call-template name = 菜单列表 / >
< / ul >
< / xsl:if >
< / li >
< / xsl:template >
< / xsl:stylesheet >









现在看看大胆的部分。

我想添加此属性,如果IsChecked的值被发现为已检查,否则我不想添加此属性。

解决方案

试试这个



 <   xsl:if     test   = 菜单/ checked ='True'    xmlns:xsl   = #unknown >  
< xsl:attribute 名称 = 选中 >
< xsl:value-of 选择 = IsChecked / >
< / xsl:attribute >
< / xsl:if >


Hi All,
I am generating html by using xml. My database gives me value as
menuid name parentid IsChecked
1 Hotel null checked
2 Resort 1
3 Swiming Pool 2 checked

i have create xml file like this


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"

>
  <xsl:output method="xml" indent="yes" encoding="utf-8"/>

  <xsl:template match="/Menus">
    <ul>


      <xsl:call-template name="MenuListing" />
    </ul>
  </xsl:template>
  <!-- Allow for recusive child node processing -->
  <xsl:template name="MenuListing">
    <xsl:apply-templates select="Menu" />
  </xsl:template>

  <xsl:template match="Menu">
    <li>
      <a>
        <!--   Convert Menu child elements to <li> <a> html tags and  add attributes inside <a> tag -->
        <xsl:attribute name="href">
          <xsl:value-of select="url"/>
        </xsl:attribute>
        <xsl:value-of select="name"/>
      </a>
      <input>
        <xsl:attribute name="id">
          <xsl:value-of select="menuid"/>
        </xsl:attribute>
        <xsl:attribute name="type">
          <xsl:text>checkbox</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="class">
          <xsl:text>selectCat</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="checked">
          <xsl:value-of select="IsChecked"/>
        </xsl:attribute>
      </input>


      <!-- Call MenuListing if there are child Menu nodes -->
      <xsl:if test="count(Menu) > 0">
        <ul>
          <xsl:call-template name="MenuListing" />
        </ul>
      </xsl:if>
    </li>
  </xsl:template>
</xsl:stylesheet>





now look into bold part.
I want to add this attribute if the value of IsChecked found as checked else i don't want to add this attribute.

解决方案

Try this

<xsl:if test="Menu/checked='True'" xmlns:xsl="#unknown">
   <xsl:attribute name="checked">
       <xsl:value-of select="IsChecked" />
   </xsl:attribute>
</xsl:if>


这篇关于从数据库生成的xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆