[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: changing section of XML file

Subject: RE: changing section of XML file
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 9 Dec 2008 21:42:41 -0000
RE:  changing section of XML file
This looks like a very straightforward transformation, you don't make it
clear where your difficulty lies. Or are you just asking if someone can
write the code for you?

The coding pattern for this is to write an "identity template" that copies
elements unchanged:

<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

and then supplement it with overriding rules for elements that need to
change, for example

<xsl:template match="rpc">
  <rpc rpcname="Sikorsky">
    <xsl:apply-templates/>
  </rpc>
</xsl:template>

<xsl:template match="applic"> 
  <applic>
    <model model="{//modellic}">
      <mfc><xsl:value-of select="../rpc"/></mfc>
      <pnr><xsl:value-of select="//modellic"/></pnr>
      <serialno><single>ALL</single></serialno>
    </model>
  </applic>
</xsl:template>

I don't know if XMLSpy has the facility to apply a transformation to 1000
input files: I suspect not. A good tool for this might be Kernow.
Alternatively, XSLT 2.0 has facilities for selecting a collection of input
files and creating a set of corresponding output files within the language
itself.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Furst, Tom [mailto:tom.furst@xxxxxxxx] 
> Sent: 09 December 2008 20:27
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  changing section of XML file
> 
> I need to change a section of an XML document per a 
> customer's requirements.
> 
> The existing section is:
> 
> <status>
> <security class="01"/>
> <rpc>78286</rpc>
> <orig>1DXU0</orig> (this section is sometimes 78286 dependnig 
> on date of generation) <applic></applic> 
> <brexref><refdm><avee><modelic>CH148</modelic><sdc
> >A</sdc><chapnum>00</chapnum><section>4</section><subsect>0</subsect>
> <subject>00</subject><discode>00</discode><discodev>A</discode
> v><incode
> >022</incode><incodev>A</incodev><itemloc>D</itemloc></avee></refdm>
> </brexref>
> <qa>
> <unverif/></qa>
> </status>
> 
> It needs to change to:
> 
> <status>
> <security class="01"/>
> <rpc rpcname="Sikorsky">78286</rpc>
> <orig origname="Sikorsky">78286</orig>
> <applic><model model="CH148">
> <mfc>78286</mfc>
> <pnr>CH148</pnr>
> <serialno><single>ALL</single></serialno></model></applic>
> <brexref><refdm><avee><modelic>CH148</modelic><sdc>A</sdc><cha
> pnum>00</chapnum>
> <section>4</section><subsect>0</subsect><subject>00</subject><
> discode>00</discode>
> <discodev>A</discodev><incode>022</incode><incodev>A</incodev>
> <itemloc>D</itemloc>
> </avee></refdm></brexref>
> <qa><firstver type="tabtop"/></qa>
> <rfu>Conversion to S1000D</rfu>
> </status>
> 
> The file is validated by a schema.
> 
> I would like to create an XSLT file to handle this transform 
> to help speed up the process. I have on the order of 1000 
> files that this will need to be done to, and currently it is 
> being handled one by one in textpad.
> 
> I would like to accomplish this with XSLT 1.0. I am not sure 
> of my processor. I will be using XML Spy to work the files, 
> which I believe has a processor built in.
> 
> 
> Thanks,
> 
> Tom Furst
> Technical Writer
> 
> Phone 401-315-6411
> Fax     401-315-6412
> tom.furst@xxxxxxxx

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.