以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  请教关于变量、 生成属性的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=23943)


--  作者:追
--  发布时间:11/4/2005 4:25:00 PM

--  请教关于变量、 生成属性的问题
各位高手,这样还是不行啊
在原xml文档中有节点:
<字:斜体 locID="t0089" 字:值="true" attrList="值"/>
a.xsl
<xsl:variable name="font-style">
<xsl:choose>
<xsl:when test="字:斜体/@字:值=true">italic</xsl:when>
<xsl:otherwise> </xsl:otherwise>
</xsl:choose>
</xsl:variable>
<span><xsl:attribute name="style">font-style:<xsl:value-of select="$font-style"/></xsl:attribute>
<span>
可字体并没按要求出现阿
--  作者:skyhaha
--  发布时间:11/4/2005 4:43:00 PM

--  
xml:
<appendix>
 <斜体 locID="t0089" 值="true" attrList="值"/>
</appendix>
xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:template match="/">
          <xsl:apply-templates select="appendix/斜体"/>
     </xsl:template>
     
     <xsl:template match="斜体">
          <xsl:variable name="font-style">
          <xsl:if test="@值='true'">
            italic
          </xsl:if>
          </xsl:variable>
          <span><xsl:attribute name="style">font-style:<xsl:value-of select="$font-style"/></xsl:attribute>看看这里</span>
    </xsl:template>
</xsl:stylesheet>


--  作者:追
--  发布时间:11/4/2005 11:26:00 PM

--  
我想知道用<when> 和<otherwise>为什么不行?
因为我要根据不同条件赋好几个值阿
--  作者:skyhaha
--  发布时间:11/6/2005 10:03:00 PM

--  
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:template match="/">
          <xsl:apply-templates select="appendix/斜体"/>
     </xsl:template>
     
     <xsl:template match="斜体">
          <xsl:variable name="font-style">
 <xsl:choose>
    <xsl:when test="@值='true'">italic</xsl:when>
    <xsl:otherwise></xsl:otherwise>
 </xsl:choose>
          </xsl:variable>
          <span><xsl:attribute name="style">font-style:<xsl:value-of select="$font-style"/></xsl:attribute>看看这里</span>
    </xsl:template>
</xsl:stylesheet>
--  作者:skyhaha
--  发布时间:11/6/2005 10:10:00 PM

--  
你的方法没有错,你“仔细”看看你错在那里,我写的和你写的有什么不同,看到你的错误下次就不会犯了
--  作者:追
--  发布时间:11/9/2005 1:08:00 PM

--  
谢谢大家了!已经搞定 呵呵
不过还想请教一个问题:
我的XML文档里面有Unicode代码,也就是图片的机器码,(我也不知道那是什么码,反正是人不认识,用机器翻译的代码,呵呵)
我怎么用xslt转换出来后显示图片,而不是原来的那种不认识的机器码?
请大家多多指教
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms