Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 April 27th, 2004, 09:32 AM
Authorized User
 
Join Date: Apr 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Applying an XSLT to an XML document (II)

I am new to XSLT and I am trying to apply an XSL transformation to an XML cutting a lot of stuff from the xml file.
The xml file follows:

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
    xmlns:rs='urn:schemas-microsoft-com:rowset'
    xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
    <s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'>
        <s:AttributeType name='id' rs:number='1' rs:writeunknown='true'>
            <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/>
        </s:AttributeType>
        <s:AttributeType name='Brand' rs:number='2' rs:nullable='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50'/>
        </s:AttributeType>
        <s:AttributeType name='model' rs:number='3' rs:nullable='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50'/>
        </s:AttributeType>
        <s:AttributeType name='capacity' rs:number='4' rs:nullable='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50'/>
        </s:AttributeType>
        <s:extends type='rs:rowbase'/>
    </s:ElementType>
</s:Schema>
<rs:data>
    <z:row id='1' Brand='Alfa Romeo' model='147' capacity='2.0'/>
    <z:row id='2' Brand='Alfa Romeo' model='156' capacity='3.2'/>
    <z:row id='3' Brand='Audi' model='A3' capacity='1.8T'/>
    <z:row id='4' Brand='Audi' model='A4' capacity='2.5'/>
    <z:row id='5' Brand='Citroen' model='C2' capacity='1.1'/>
    <z:row id='6' Brand='Maserati' model='Quattroporte' capacity='3.0'/>
    <z:row id='7' Brand='Volvo' model='S40' capacity='1.8'/>
</rs:data>
</xml>

and I am interested only to the data that are between the </rs:data> tags.
How would look an xsl file that would produce an xml output like the following?

<?xml version="1.0" encoding="iso-8859-7" standalone="yes" ?>
<rss version="0.91">
  <channel>
    <title>Help from p2p.wrox.com</title>
    <link>NULL</link>
    <description>A classification of car models</description>
    <language>en</language>
    <item>
      <title>Alfa Romeo</title>
      <link>NULL</link>
      <description>147</description>
    </item>
    <item>
      <title>Audi</title>
      <link>NULL</link>
      <description>A3</description>
    </item>
    <item>
      <title>Citroen</title>
      <link>NULL</link>
      <description>C2</description>
    </item>
  </channel>
</rss>


 
Old April 28th, 2004, 09:10 AM
Authorized User
 
Join Date: Apr 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The xsl that would answer the question would have the following format:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:rs="urn:schemas-microsoft-com:rowset"
              xmlns:z="#RowsetSchema">

The template structure implementation depends on the way you would like to view the contents. My problem was to parse <rs:data> and <z:row> elements.


Thodoris.



Quote:
quote:Originally posted by Thodoris
 I am new to XSLT and I am trying to apply an XSL transformation to an XML cutting a lot of stuff from the xml file.
The xml file follows:

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
    xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
    xmlns:rs='urn:schemas-microsoft-com:rowset'
    xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
    <s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'>
        <s:AttributeType name='id' rs:number='1' rs:writeunknown='true'>
            <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' rs:fixedlength='true' rs:maybenull='false'/>
        </s:AttributeType>
        <s:AttributeType name='Brand' rs:number='2' rs:nullable='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50'/>
        </s:AttributeType>
        <s:AttributeType name='model' rs:number='3' rs:nullable='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50'/>
        </s:AttributeType>
        <s:AttributeType name='capacity' rs:number='4' rs:nullable='true' rs:writeunknown='true'>
            <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50'/>
        </s:AttributeType>
        <s:extends type='rs:rowbase'/>
    </s:ElementType>
</s:Schema>
<rs:data>
    <z:row id='1' Brand='Alfa Romeo' model='147' capacity='2.0'/>
    <z:row id='2' Brand='Alfa Romeo' model='156' capacity='3.2'/>
    <z:row id='3' Brand='Audi' model='A3' capacity='1.8T'/>
    <z:row id='4' Brand='Audi' model='A4' capacity='2.5'/>
    <z:row id='5' Brand='Citroen' model='C2' capacity='1.1'/>
    <z:row id='6' Brand='Maserati' model='Quattroporte' capacity='3.0'/>
    <z:row id='7' Brand='Volvo' model='S40' capacity='1.8'/>
</rs:data>
</xml>

and I am interested only to the data that are between the </rs:data> tags.
How would look an xsl file that would produce an xml output like the following?

<?xml version="1.0" encoding="iso-8859-7" standalone="yes" ?>
<rss version="0.91">
<channel>
    <title>Help from p2p.wrox.com</title>
    <link>NULL</link>
    <description>A classification of car models</description>
    <language>en</language>
    <item>
     <title>Alfa Romeo</title>
     <link>NULL</link>
     <description>147</description>
    </item>
    <item>
     <title>Audi</title>
     <link>NULL</link>
     <description>A3</description>
    </item>
    <item>
     <title>Citroen</title>
     <link>NULL</link>
     <description>C2</description>
    </item>
</channel>
</rss>







Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt document function.. maddukuri XSLT 8 May 16th, 2008 06:31 AM
xslt document() function problem with servlet meps XSLT 3 December 20th, 2005 10:34 AM
Problem applying simple XSLT to XML to create CSV gregclark XSLT 2 August 25th, 2005 07:30 AM
xslt 2.0 document function jkmyoung XSLT 2 November 18th, 2004 03:21 PM
Applying an XSLT to an XML document dimondwoof XML 1 June 26th, 2003 01:22 PM





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