Correct XML Path to a specific node?


I have been poring over the following for ages now and just can’t find out what is going wrong.
Thus, another set of XML-savvy eyes would be greatly appreciated!

This is a relevant snippet of the XML that I want to transform via XSLT:

				<string>The text I'm trying to select.</string>
				<string>Your Description</string>

I want to select the content of the <string> following <key>'s with “plainText” as content,
but only in <dict>'s where the string following key=‘source’ is “Your description”.

I’ve set the XSL up like this:

<!-- data is contained in an array: applies to synopses -->
                <xsl:when test="$dataname='synopses'">
                    <!-- only import own synopses -->
                    <xsl:if test="following-sibling::array[1]/dict/key['source']/following-sibling::string[1]/text()='Your Description'">
                        <xsl:value-of select="following-sibling::array[1]/dict/key['plainText']/following-sibling::string[1]"/>

While I do get the content of the string I want with this, the string “Your Description” is also appended to it in my resulting XML, like so:

<synopsis>The text I'm trying to select. Your Description</synopsis>

But I have NO idea how that “Your Description” is getting pulled in?
It is as if the last string[1] is being ignored??

Thanks for any pointers here,

Meanwhile I have continued to search for whatever was causing the erroneous results and have come up with the following solution:

<xsl:when test="$dataname='synopses'">

           <xsl:value-of select="following-sibling::array[1]/dict[string='Your Description']/string[1]"/>


Basically, I simplified the whole matter by discarding

  • the if-statement by including the condition of the dict having to contain “Your Description” within the select-string itself
  • the second use of following-sibling::string, since I suspect something was going wrong there level - wise (though unfortunately I was not able to find out how exactly the path must be defined to make such specific instructions work).

Being as it is less specific in keeping the key-string pairs together, there is of course the danger of extracting the wrong information if source’s producer decides to change the order of elements, but there is a fair chance that that won’t be the case.

If anyone knows why my first path wasn’t working right, I would still be very interested to know!
Thanks again