RE: [xsl] changing section of XML file

Subject: RE: [xsl] changing section of XML file
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 9 Dec 2008 21:42:41 -0000
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: [xsl] 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