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

Subject: Re: [xsl] Replacing values in the input file with values from a second file
From: Mark Peters <flickrmeister@xxxxxxxxx>
Date: Tue, 7 Apr 2009 10:33:28 -0400
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@xxxxxxxxxxxx> 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[@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@xxxxxxxxx]
>> Sent: 07 April 2009 14:15
>> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> 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">
>> B  B <title>Menus</title>
>> B  B <topic id="AB">
>> B  B  B  <title>Menu AB Details</title>
>> B  B  B  <body>
>> B  B  B  B  B <p id="AB1">
>> B  B  B  B  B  B  <uicontrol conref="AB1a"/>
>> B  B  B  B  B </p>
>> B  B  B  B  B <p id="AB2">
>> B  B  B  B  B  B  <uicontrol conref="AB2a"/>
>> B  B  B  B  B  <uicontrol conref="AB2b"/>
>> B  B  B  B  B </p>
>> B  B  B  B </body>
>> B  B  </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">
>> B  B <title>Navigation Labels</title>
>> B  B <body>
>> B  B  B  <p><uicontrol id="AB1a">Oranges</uicontrol></p>
>> B  B  B  <p><uicontrol id="AB2a">Apples</uicontrol></p>
>> B  B  B  <p><uicontrol id="AB3b">Bananas</uicontrol></p>
>> B  B </body>
>> </topic>
>>
>>
>> Here is the output I'm trying to produce:
>>
>> <topic id="A">
>> B  B <title>Menus</title>
>> B  B <topic id="AB">
>> B  B  B  <title>Menu AB Details</title>
>> B  B  B  <body>
>> B  B  B  B  B <p id="AB1">
>> B  B  B  B  B  B  <uicontrol>Oranges</uicontrol>
>> B  B  B  B  B </p>
>> B  B  B  B  B <p id="AB2">
>> B  B  B  B  B  B  <uicontrol>Apples</uicontrol>
>> B  B  B  B  B  <uicontrol>Bananas</uicontrol>
>> B  B  B  B  B </p>
>> B  B  B  B </body>
>> B  B  </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">
>> B  B  B  <xsl:output method="xml"/>
>>
>> B  B  B  <xsl:template match="node()|@*">
>> B  B  B  B  B  B  B  <xsl:copy>
>> B  B  B  B  B  B  B  B  B  B  B  <xsl:apply-templates select="@*"/>
>> B  B  B  B  B  B  B  B  B  B  B  <xsl:apply-templates/>
>> B  B  B  B  B  B  B  </xsl:copy>
>> B  B  B  </xsl:template>
>> B  B  B  <xsl:template match="uicontrol">
>> B  B  B  B  B  B  B  <uicontrol>
>> B  B  B  B  B  B  B  B  B  B  B  <xsl:value-of
>> select="document('navigation-labels.xml')/topic/body/p/uicontr
>> ol[document('navigation-labels.xml')/topic/body/p/uicontrol
>> = .]"/>
>> B  B  B  B  B  B  B  </uicontrol>
>> B  B  B  </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">
>> B  B <title>Menus</title>
>> B  B <topic id="AB">
>> B  B  B  <title>Menu AB Details</title>
>> B  B  B  <body>
>> B  B  B  B  B <p id="AB1">
>> B  B  B  B  B  B  <uicontrol>Oranges</uicontrol>
>> B  B  B  B  B </p>
>> B  B  B  B  B <p id="AB2">
>> B  B  B  B  B  B  <uicontrol>Oranges</uicontrol>
>> B  B  B  B  B  <uicontrol>Oranges</uicontrol>
>> B  B  B  B  B </p>
>> B  B  B  B </body>
>> B  B  </topic>
>> </topic>
>>
>>
>> Thanks in advance for any help!
>>
>> Mark
>>
>> --
>>
>> Mark Peters
>> Senior Technical Writer
>> Saba Software
>
>



--

Mark Peters
Senior Technical Writer
Saba Software

Current Thread