以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  [求助]用import合并xsl  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=45170)


--  作者:路人随心
--  发布时间:4/10/2007 7:44:00 PM

--  [求助]用import合并xsl
大侠们帮忙看下

test_main.xml

<test>
      aaaa
</test>

hebing.xsl

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

   <xsl:import href="test1.xsl"/>
   <xsl:import href="test2.xsl"/>

</xsl:stylesheet>


test1.xsl

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

 <xsl:template match="test">
  <p>bbbb</p>
 </xsl:template>
</xsl:stylesheet>


test2.xsl

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

 <xsl:template match="test">
  <p>cccc</p>
 </xsl:template>
</xsl:stylesheet>


我想用hebing.xsl同时调用test1.xsl和test2.xsl    可是结果只有test2.xsl的(就是结果只显示cccc)

请问怎样改才能显示  bbbb cccc    

[此贴子已经被作者于2007-4-10 20:22:21编辑过]

--  作者:Qr
--  发布时间:4/11/2007 9:11:00 AM

--  
待xsl:import 的XSL全部写成模板,在主XSL中通过<xsl:call-template>来调用。

--  作者:hexun831012
--  发布时间:4/11/2007 9:12:00 AM

--  
关键在于模版
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="test1.xsl"/>
  <xsl:import href="test2.xsl"/>
</xsl:stylesheet>
就等于
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="test">
    <p>bbbb</p>
  </xsl:template>
  <xsl:template match="test">
    <p>cccc</p>
  </xsl:template>
</xsl:stylesheet>
所以根据xsl的解析顺序,是从下到上的,自然上一个模版会被下一个模版屏蔽
--  作者:Qtian
--  发布时间:5/8/2007 8:30:00 PM

--  
我是这样使用的:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:Missde="MissdeVBS" xmlns:MissdeJS="MissdeJS">

<xsl:import href="要插入的子xsl文件.xsl"/>


<xsl:template match="html">
<html>
<xsl:call-template name="子xsl名称"/>
<body>

----------------


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:template name="子xsl名称">
dddddddddddddddddddddd
</xsl:template>
</xsl:stylesheet>


--  作者:hexun831012
--  发布时间:5/9/2007 9:18:00 AM

--  
xsl不接受默认命名空间,你要为你的命名空间起个别名
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms