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

Fw: Replacing values in the input file with values fro

Subject: Fw: Replacing values in the input file with values from a second file
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Tue, 7 Apr 2009 18:52:23 +0200
Fw:  Replacing values in the input file with values fro
Martin,

nice, but the Bananas are missing ...

[stammw twoFiles]$ xsltproc doit.xsl doc.xml
<?xml version="1.0"?>
<topic id="A">
   <title>Menus</title>
   <topic id="AB">
      <title>Menu AB Details</title>
      <body>>
         <p id="AB1">
            <uicontrol>Oranges</uicontrol>
         </p>
         <p id="AB2">
            <uicontrol>Apples</uicontrol>>
                     <uicontrol></uicontrol>
         </p>
       </body>
    </topic>
</topic>
rh73[main]-[stammw twoFiles]$



Mit besten Gr|_en / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschdftsf|hrung: Erich Baier
Sitz der Gesellschaft: Bvblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
----- Forwarded by Hermann Stamm-Wilbrandt/Germany/IBM on 04/07/2009 06:50
PM -----

             Martin Honnen
             <Martin.Honnen@gm
             x.de>                                                      To
                                       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
             04/07/2009 03:29                                           cc
             PM
                                                                   Subject
                                       Re:  Replacing values in the
             Please respond to         input file with values from a
             xsl-list@xxxxxxxx         second file
              lberrytech.com









Mark Peters wrote:
> Hi Everyone,
>
> I have a seemingly simple transformation project, but there is a piece
> of the puzzle that I'm missing. Maybe the solution isn't so simple,
> after all. :-)
>
>
> Here is my input file.
>
> <topic id="A">
>    <title>Menus</title>
>    <topic id="AB">
>       <title>Menu AB Details</title>
>       <body>
>          <p id="AB1">
>             <uicontrol conref="AB1a"/>
>          </p>
>          <p id="AB2">
>             <uicontrol conref="AB2a"/>
>                <uicontrol conref="AB2b"/>
>          </p>
>        </body>
>     </topic>
> </topic>
>
> For each uicontrol element, I'd like to substitute the element value
> in a second file, whose id attribute value corresponds to the conref
> value in the first file.
>
> Here is the second file (navigation-labels.xml):
>
> <topic id ="navigation-labels">
>    <title>Navigation Labels</title>
>    <body>
>       <p><uicontrol id="AB1a">Oranges</uicontrol></p>
>       <p><uicontrol id="AB2a">Apples</uicontrol></p>
>       <p><uicontrol id="AB3b">Bananas</uicontrol></p>
>    </body>
> </topic>
>
>
> Here is the output I'm trying to produce:
>
> <topic id="A">
>    <title>Menus</title>
>    <topic id="AB">
>       <title>Menu AB Details</title>
>       <body>
>          <p id="AB1">
>             <uicontrol>Oranges</uicontrol>
>          </p>
>          <p id="AB2">
>             <uicontrol>Apples</uicontrol>
>                <uicontrol>Bananas</uicontrol>
>          </p>
>        </body>
>     </topic>
> </topic>

Here is an example stylesheet:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:output indent="yes"/>

   <xsl:key name="uic" match="uicontrol" use="@id"/>

   <xsl:variable name="uic-doc" select="document
('navigation-labels.xml')"/>

   <xsl:template match="uicontrol">
     <xsl:variable name="ref" select="@conref"/>
     <xsl:copy>
       <xsl:for-each select="$uic-doc">
         <xsl:value-of select="key('uic', $ref)"/>
       </xsl:for-each>
     </xsl:copy>
   </xsl:template>

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

--

             Martin Honnen
             http://JavaScript.FAQTs.com/:

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.