Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2004, 02:21 PM
Registered User
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default a simple problem

Hi all,

I know my question is very basic. I am a newbie and couldn't find a similar code.
I have the original xml like this:
<gxl>
     <graph>
             <node id="0"
                    <attr name = "label">
                            <string>something</string>
                    </attr>
                    <attr name = "font"
                     ...
              </node>
              <node id =
               ...
      </graph>
</gxl>

And I'd like to make an xslt to output an xml like
<state>
      <Name>Node id</Name>
      <Condition>something</Condition>
</state>
<state>
..
</state>

I mean i want to get the Node id to place in the <Name> tag of state.
Each Node is a State in my out xml. If the attr name of Node is label, I get the string and put in tag Condition.
How can I do that ?

Please help me with this small example.
Thank you very much !
Suzy.

 
Old February 27th, 2004, 06:17 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well if your xml is
Code:
<gxl>
  <graph>
    <node id="0">
      <attr name="label">
        <string>label0</string>
      </attr>
      <attr name="font">
        <string>font</string>
      </attr>
    </node>             
    <node id="1">
      <attr name="label">
        <string>label1</string>
      </attr>
      <attr name="font">
        <string>font</string>
      </attr>
    </node>             
    <node id="2">
      <attr name="font">
        <string>font</string>
      </attr>
    </node>             
    <node id="3">
      <attr name="label">
        <string>label3</string>
      </attr>
      <attr name="font">
        <string>font</string>
      </attr>
    </node>             
  </graph>
</gxl>
then you want something along the lines of
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <states>
      <xsl:apply-templates select="gxl/graph/node"/>
    </states>
  </xsl:template>

  <xsl:template match="node">
    <state>
      <name><xsl:value-of select="@id"/></name>
      <xsl:if test="attr[@name = 'label']">
        <condition><xsl:value-of select="attr[@name = 'label']/string"/></condition>
      </xsl:if>
    </state>  
  </xsl:template>
</xsl:stylesheet>
which selects all the node eleemnts and adds the surrounding markup. There is also a conditional test for an attr with a attribute name of label.

Joe (MVP - xml)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple != problem akentanaka XSLT 3 October 13th, 2008 11:54 PM
A Simple Problem paole Wrox Book Feedback 7 July 23rd, 2007 08:55 PM
Simple Problem Little Shell XML 2 June 5th, 2006 03:30 PM
Simple problem rsa3des Classic ASP Basics 4 August 8th, 2005 06:14 PM
Simple Problem bsdb3 Java GUI 2 February 5th, 2004 09:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.