LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-18-2004, 02:17 PM   #1
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Question xml parsing with xsl


I'm need to write an xsl stylesheet to remove some properties from an xml file. Since I have never used xsl before I have no clue where to start. I've sifted through various xsl tutorials, but most examples I've seen convert xml to html and I'm not doing that.

The stuff I need to convert is below. I need to remove all the <array Items> and set the array property length to 0.

The action class will always = "com.installshield.product.actions.Files" but the ID will be different. There are multiple <actions class= > in the file and I need them all converted.

Any help/examples you can provide would be great.


This is what I need converted:
Code:
                <action class="com.installshield.product.actions.Files" id="files-SQLServer">
                    <displayName>Files-SQLServer</displayName>
                    <active>true</active>
                    <buildCategories/>
                    <property array="True" length="14" name="files" type="com.installshield.product.actions.SourceFile">
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File1.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File2.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File3.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File4.exe.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File5.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File6.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File7.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File8.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File9.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File10.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File11.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File12.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(SERVER_HOME)/Bin/Server/File13.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">0</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                        <arrayItem type="com.installshield.product.actions.SourceFile">
                            <property name="resolveRuntimeFileName">False</property>
                            <property name="fileName">$A(BUILD_HOME)/Bin/Server/File14.exe</property>
                            <property name="usingGNUPattern">False</property>
                            <property name="pathForFiltering">1</property>
                            <property name="includeSubdirs">False</property>
                            <property name="entryType">1</property>
                            <property name="usingGNUExcludePattern">False</property>
                            <property name="fileType">0</property>
                        </arrayItem>
                    </property>
                    <property name="totalBytes">-1</property>
                    <property name="owner"/>
                    <property name="group"/>
                    <property name="storedAs">0</property>
                    <property name="externalResourceLocation"/>
                    <property name="externalResourceMediaId">1</property>
                </action>

This is what I need it to convert to:
Code:
                <action class="com.installshield.product.actions.Files" id="files-SQLServer">
                    <displayName>Files-SQLServer</displayName>
                    <active>true</active>
                    <buildCategories/>
                    <comments/>
                    <property array="True" length="0" name="files" type="com.installshield.product.actions.SourceFile"/>
                    <property name="totalBytes">-1</property>
                    <property name="owner"/>
                    <property name="group"/>
                    <property name="replaceType">100</property>
                    <property name="useJARVersion">False</property>
                    <property name="storedAs">0</property>
                    <property name="externalResourceLocation"/>
                    <property name="externalResourceMediaId">1</property>
                </action>
 
Old 03-19-2004, 02:56 PM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Original Poster
Rep: Reputation: 120Reputation: 120
Ended up being very easy:
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

   <xsl:output method="xml" />

   <xsl:template match="*|@*">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
	</xsl:template>

   <xsl:template match="action[@class='com.installshield.product.actions.Files']/property[@name='files']">
      <property array="True" length="0" name="files" type="com.installshield.product.actions.SourceFile"/>
   </xsl:template>

</xsl:stylesheet>
 
Old 03-22-2004, 02:45 AM   #3
gr33ndata
Member
 
Registered: Aug 2003
Location: DMZ
Distribution: Ubuntu
Posts: 144

Rep: Reputation: 15
why not use libxml it is much prettier
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help to strip XML & XSL tags from multiple files dfrechet Programming 9 10-12-2005 07:52 AM
XSL need help translating XML to html hyperlink qwijibow Programming 1 03-09-2005 05:36 PM
Docbook XSL Stylesheets /etc/xml/catalog Ironica Linux - Software 0 12-10-2004 04:03 AM
XML and XSL Kedelfor Programming 4 09-13-2004 06:30 PM
Xerces, Xalan -- XML + XSL = HTML marktaff Linux - Software 1 10-15-2002 11:01 PM


All times are GMT -5. The time now is 02:02 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration