xsl-list
[Top] [All Lists]

Re: [xsl] Replacing values in the input file with values from a second file

2009-04-07 10:33:58
Thanks Martin, Andrew, and Michael!  My goodness, you're quick!

Quite how you expected this to work when your code references neither the
@id nor @conref attributes defeats me.

You're right, of course, Michael. That was a careless mistake. The
xsl:if and xsl:choose statements I tried earlier did reference the @id
and @conref attributes, but I apparently either constructed them or
placed them incorrectly.

Off to read about keys.

Thanks again,
Mark


On Tue, Apr 7, 2009 at 9:36 AM, Michael Kay <mike(_at_)saxonica(_dot_)com> 
wrote:
Replace

<xsl:value-of
select="document('navigation-labels.xml')/topic/body/p/uicontrol[document('n
avigation-labels.xml')/topic/body/p/uicontrol
= .]"/>

by

<xsl:value-of
select="document('navigation-labels.xml')/topic/body/p/uicontrol[(_at_)id =
current()/@conref]"/>

Quite how you expected this to work when your code references neither the
@id nor @conref attributes defeats me.

It would be more efficient, and perhaps clearer, to use a key - but get it
working first.

Michael Kay
http:/www.saxonica.com/

-----Original Message-----
From: Mark Peters [mailto:flickrmeister(_at_)gmail(_dot_)com]
Sent: 07 April 2009 14:15
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Replacing values in the input file with values
from a second file

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>


I've tried if statements and choose statements. Here is my
current transformation.

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

      <xsl:template match="node()|@*">
              <xsl:copy>
                      <xsl:apply-templates select="@*"/>
                      <xsl:apply-templates/>
              </xsl:copy>
      </xsl:template>
      <xsl:template match="uicontrol">
              <uicontrol>
                      <xsl:value-of
select="document('navigation-labels.xml')/topic/body/p/uicontr
ol[document('navigation-labels.xml')/topic/body/p/uicontrol
= .]"/>
              </uicontrol>
      </xsl:template>
</xsl:stylesheet>


And here is the current output. For each uicontrol element,
the transformation is substituting the first uicontrol
element value in the navigation-labels.xml file, rather than
the value from the corresponding uicontrol element.

<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>Oranges</uicontrol>
          <uicontrol>Oranges</uicontrol>
         </p>
       </body>
    </topic>
</topic>


Thanks in advance for any help!

Mark

--

Mark Peters
Senior Technical Writer
Saba Software

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





-- 

Mark Peters
Senior Technical Writer
Saba Software

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--