以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  用xml数据自动生成svg  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=49191)


--  作者:zhengminxin
--  发布时间:6/29/2007 11:37:00 AM

--  用xml数据自动生成svg
相信各位都已经读过IBM上的这个例子(https://www6.software.ibm.com/developerworks/cn/education/xml/x-iactsvg/tutorial/index.html)

这是个用SVG创建楼层平面图的例子,其中有用到xslt转换xml数据自动生成svg,可是在我的机器上看不到正确的结果,请问各位大侠是什么原因?


--  作者:zhengminxin
--  发布时间:6/29/2007 11:38:00 AM

--  
room.xml文件内容

<?xml   version='1.0'?>
<?xml-stylesheet   href="room.xsl"   type="text/xsl"?>
<RoomData>
  <Room   position="1"   type="Standard"   width="40"   depth="25"   />
  <Room   position="2"   type="Standard"   width="40"   depth="22"   />
  <Room   position="3"   type="Standard"   width="40"   depth="25"   />
</RoomData>


--  作者:zhengminxin
--  发布时间:6/29/2007 11:38:00 AM

--  
room.xsl文件内容

<?xml   version='1.0'?>
<xsl:stylesheet   version="1.0"     
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   
                xmlns:xlink="http://www.w3.org/1999/xlink"   
                xmlns="http://www.w3.org/2000/svg">
  <xsl:output   method="xml"   indent="yes"   encoding="UTF-8"   />

  <xsl:template   match="/">

    <svg   xmlns:xlink="http://www.w3.org/1999/xlink"     
                xmlns="http://www.w3.org/2000/svg"   
                width="1200px"   height="250px"   viewBox="0   0   400   250"     
                id="RoomsSVG">

      <g   id="mover"   transform="translate(-400,0)">
        <xsl:apply-templates   select="Room"   />
      </g>
    </svg>
  </xsl:template>

  <xsl:template   match="Room">
    <xsl:element   name="svg">
      <xsl:attribute   name="id">
        <xsl:value-of     
                  select="concat('Room10',   @position)"   />
      </xsl:attribute>
      <xsl:attribute   name="width">
        <xsl:value-of     
                  select="(10   *   @width)"   />px
      </xsl:attribute>
      <xsl:attribute   name="height">
        <xsl:value-of     
                  select="(10   *   @depth)"   />px
      </xsl:attribute>
      <xsl:attribute   name="x">
        <xsl:value-of     
                  select="concat(((@position   -   1)   *   400),   'px')"   />
      </xsl:attribute>
      <xsl:attribute   name="y">0px</xsl:attribute>

      <xsl:element   name="rect">
        <xsl:attribute   name="id">
          <xsl:value-of   
                  select="concat('Room10',   @position,   'Rect')"   />
        </xsl:attribute>
        <xsl:attribute   name="width">100%</xsl:attribute>
        <xsl:attribute   name="height">100%</xsl:attribute>
        <xsl:choose>
          <xsl:when   test="@position='1'">
            <xsl:attribute   name="fill">#CCCCFF</xsl:attribute>
          </xsl:when>
          <xsl:when   test="@position='2'">
            <xsl:attribute   name="fill">#CCFFCC</xsl:attribute>
          </xsl:when>
          <xsl:when   test="@position='3'">
            <xsl:attribute   name="fill">#FFCC00</xsl:attribute>
          </xsl:when>
        </xsl:choose>
        <xsl:attribute   name="stroke">black</xsl:attribute>
        <xsl:attribute   name="stroke-width">5</xsl:attribute>
      </xsl:element>
      <!--   End   of   rect   Element   -->
      <xsl:element   name="text">
        <xsl:attribute   name="id">
          <xsl:value-of     
                  select="concat('Room10',   @position,   'Label')"   />
        </xsl:attribute>
        <xsl:attribute   name="font-size">24pt</xsl:attribute>
        <xsl:attribute   name="x">55px</xsl:attribute>
        <xsl:attribute   name="y">100px</xsl:attribute>
        <xsl:attribute   name="fill">black</xsl:attribute>
        Room   10<xsl:value-of   select="@position"   />
      </xsl:element>
      <!--   End   of   first   text   Element   -->

      <xsl:element   name="text">
        <xsl:attribute   name="id">
          <xsl:value-of     
                  select="concat('Room10',   @position,   'Type')"   />
        </xsl:attribute>
        <xsl:attribute   name="font-size">24pt</xsl:attribute>
        <xsl:attribute   name="x">55px</xsl:attribute>
        <xsl:attribute   name="y">150px</xsl:attribute>
        <xsl:attribute   name="fill">black</xsl:attribute>
        <xsl:value-of   select="@type"   />   office
      </xsl:element>
      <!--   End   of   second   text   Element   -->

      <xsl:element   name="a">
        <xsl:attribute   name="xlink:href">Rooms2ndFloor.html</xsl:attribute>

        <xsl:element   name="text">
          <xsl:attribute   name="id">
            <xsl:value-of     
                  select="concat('Room10',   @position,   'Link')"   />
          </xsl:attribute>
          <xsl:attribute   name="font-size">15pt</xsl:attribute>
          <xsl:attribute   name="x">55px</xsl:attribute>
          <xsl:attribute   name="y">200px</xsl:attribute>
          <xsl:attribute   name="fill">black</xsl:attribute>
          Click   to   view   2nd   Floor
        </xsl:element>
        <!--   End   of   third   text   Element   -->

      </xsl:element>
      <!--   End   of   the   <a>   Element   -->

    </xsl:element>
    <!--   End   of   nested   svg   Element   -->
  </xsl:template>

</xsl:stylesheet>


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms