LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   xml parsing with xsl (https://www.linuxquestions.org/questions/programming-9/xml-parsing-with-xsl-159473/)

crabboy 03-18-2004 01:17 PM

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>


crabboy 03-19-2004 01:56 PM

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>


gr33ndata 03-22-2004 01:45 AM

why not use libxml it is much prettier


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