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 5th, 2008, 03:08 AM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml to xml using xslt

Hi, iam very new to xslt. I need to transform a xml file into another format of xml file, and i only want to display certain contents from the 1st xml file. However, i keep having all the inputs from the 1st xml file. Can anyone help me identify my mistake?

[u]The first xml file</u>
<?xml version="1.0" encoding="UTF-8"?>
<labb xmlns="http://www.*************">
    <header>
        <version>1.2</version>
        <lab>
            <appointed>2</appointed>
            <id>QUEEE</id>
            <name>LL</name>
            <addr>
                <BlkNo>88</BlkNo>
                <StreetName>c</StreetName>
                <FloorNo>00</FloorNo>
                <UnitNo>77</UnitNo>
                <BuildingName>Wonderful land</BuildingName>
                <PostalCode>888888</PostalCode>
            </addr>
            <CMSCode>TTT</CMSCode>
        </lab>
        <clinic>
            <id>cln007</id>
            <name>test clinic</name>
        </clinic>
        <clinic_lab>
            <id>DS011</id>
            <name>test clinic</name>
        </clinic_lab>
        <order_submit_dt>20070908</order_submit_dt>
        <order_status_code>CM</order_status_code>
        <order_control_code>NW</order_control_code>
        <orderby>
            <id>NC</id>
            <name>TEST</name>
        </orderby>
        <priority/>
        <result_dt>20070908163003</result_dt>
        <result_msg_control>ooo</result_msg_control>
        <profile_code_list>X105482</profile_code_list>
        <profile_desc_list>BASIC(GLL)</profile_desc_list>
    </header>
    <patient>
        <name>SAMPLE TESTINg</name>
        <identity>XXX2494221</identity>

        <race>cc</race>
        <dob>19710101</dob>
        <birthYear>
            <YearOfBirth>1988</YearOfBirth>
        </birthYear>

    </patient>
</labb>


[u]
The output xml file is something like the following:
</u>
<?xml version="1.0" encoding="utf-8"?>
<Request>
<Client>
        <ClientName>Client Name 01</ClientName>
        <ClientRace>C</ClientRace>
        <ClientGender>F</ClientGender>
        <ClientNRIC>S1234567D</ClientNRIC>
</Client>
<Clinic>
        <Appointed>2</Appointed>
        <ClinicName>Clinic Name 01</ClinicName>
</Clinic>


[u]And I have written a xslt file</u>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="no" standalone="no" indent="yes" />

    <xsl:template match="/">
        <Request>
            <xsl:apply-templates ></xsl:apply-templates>
        </Request>
    </xsl:template>

    <xsl:template match="/patient">
        <ClientData>
            <ClientName>

              <xsl:value-of select="name"/>

            </ClientName>
            <ClientRace>
                <xsl:value-of select="race" />
            </ClientRace>
            <ClientGender>
                <xsl:value-of select="****" />
            </ClientGender>
</ClientData>
</xsl:template>

</xsl:stylesheet>

 Thanks.

 
Old August 5th, 2008, 03:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Change match="/patient" to match="patient". The "/patient" form would only match if the patient is the outermost element of the document, which in your case it isn't.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old August 5th, 2008, 04:00 AM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply but I have tried that, and still having the same problem.

 
Old August 5th, 2008, 04:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, I usually only spot one bug at a time when inspecting source code. The next bug (I don't guarantee it is is the last) is that your source document contains elements that are in a namespace, but you are trying to match elements in no namespace. Your stylesheet needs to declare the namespace

xmlns:p="http://www.*************"

and then use this prefix when referring to elements in the source documetn, for example match="p:patient"

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old August 5th, 2008, 05:10 AM
Registered User
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks..ya, i know it has many bugs. Been struggling to do this. Anyway, i used to delcare the namespace in the sylesheet, but i used "p/patient" instead of p:patient.






Similar Threads
Thread Thread Starter Forum Replies Last Post
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
XSLT read through XML to transform another XML dendenx2 XSLT 8 July 7th, 2005 08:18 PM
XSLT for complicated xml to xml transf. required doug@sirvisetti XSLT 3 June 17th, 2005 04:26 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





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