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 August 11th, 2006, 12:17 AM
Registered User
 
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Very confused on XML to XML conversion

Hi Gurus,
I've been trying to get my head around how to do this but no matter what I try, I'm not having any luck. I have cut down my source to attempt to clearly demonstrate what I am trying to do.

Here is my source...

<?xml version="1.0"?>
<node>
    <node>
        <node class="memory">
            <capacity units="bytes">524288</capacity>
        </node>
        <node class="processor">
            <capacity units="Hz">800000000</capacity>
        </node>
    </node>
</node>

and this is what I am trying to go to...

<?xml version="1.0"?>
<tbMachines>
    <CpuSpeed units="MHz">800000</CpuSpeed>
    <Memory>524288</Memory>
</tbMachines>

I can't work out how to choose the <node class="processor"> and put it's capacity in the <CpuSpeed> output node. I've tried templates and xsl:if 's but I always end up get the memory capacity instead. Any ideas would be much appreciated. Oh, and I would also like to divide the value of the capacity by a thousand if you happen to know the answer to that.

Thanks in advance,

Richard

Richard
 
Old August 11th, 2006, 02:16 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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

  <xsl:template match="/">
    <tblMachines>
      <CpuSpeed units="MHz">
        <xsl:value-of select="node/node/node[@class = 'processor']/capacity div 1000"/>
      </CpuSpeed>
      <Memory>
        <xsl:value-of select="node/node/node[@class = 'memory']/capacity"/>
      </Memory>

    </tblMachines>
  </xsl:template>

</xsl:stylesheet>
--

Joe (Microsoft MVP - XML)
 
Old August 11th, 2006, 02:44 AM
Registered User
 
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou! Thankyou! Thankyou!
It makes sense to me now. Have a great weekend :D:)

Richard





Similar Threads
Thread Thread Starter Forum Replies Last Post
PDF to XML conversion bcogney XSLT 7 September 21st, 2011 06:27 AM
.csv to xml conversion balakrishna XML 0 March 5th, 2007 01:07 PM
XML conversion to CSV - Problem with value ccurtiss1977 XSLT 1 December 22nd, 2006 10:40 AM
XML to XSLT conversion?? Hannibal XSLT 16 November 24th, 2006 06:52 AM
Confused about XML namespaces planoie XSLT 2 June 2nd, 2005 04:23 AM





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