Additional information not grabbed correctly in the Document Structure window (wrong xpath)

Hi guys,

I created a custom file type for XML file with the following structure:

<request id="1129" source-language="da" type="LanguageText">
    <translation destination-language="fr">
        <Text translate="true">Planlagt driftstid</Text>
    </translation>
    <current-translation>Temps de fonctionnement programmé</current-translation>
    <description>Label describing the number of hours a plant is scheduled to be in operation this year</description>
</request>

I needed to extract Text translate="true" strings (the translation will overwrite them) and it's working fine however I have challenges adding the description as Structure Information. 

Trados Studio Parser settings showing a rule for extracting text with attribute translate='true' as always translatable and tagged as structure.

Edit Rule dialog in Trados Studio with XPath rule for text with attribute translate='true', set to always translatable and structure tag type.

Edit Structure Information dialog in Trados Studio with a custom description field set to extract content from the relative XPath 'description'.

Unfortunately, only the first description is extracted as structure information and is applied to all strings.
I have tested several xpath expressions without any positive result.

Do you have any ideas?

Cheers,
Dimmo




Generated Image Alt-Text
[edited by: Trados AI at 5:56 AM (GMT 0) on 29 Feb 2024]
emoji
  • ../../description

    This xpath expression searches in the same node and the structure information was extracted properly.
    (Credit goes to my colleague Mira)

    emoji
  • Thanks for this.  I think you're highlighting an important point that  noted out in this thread about relative references:

    https://community.rws.com/product-groups/trados-portfolio/trados-studio/f/studio/40389/xml-comment-xpath

    Maybe worth a further explanation for anyone who doesn't completely follow this (it took a few times for me to understand this concept too).  The expression asks for a relative path which means the expression starts from the node (or element) you are in and not from the root of the xml file.  In this case your parser rule sets your position in the file:

    //Text[@translate="true"]

    This is an absolute expression starting from the root, resolving itself by positioning you in the <Text> node.  To get to the <description> node from here you have to traverse up the file through two nodes, and the shortform of taking a parent node is the double dot.  So, using this which was in the initial post

    //description

    will get you the absolute value of the first <description> node it finds every time you parse through the xml file to extract a segment. The <description> node is actually a child of a parent of a parent of the <Text> node you are currently in:

    <request id="1129" source-language="da" type="LanguageText">
        <translation destination-language="fr">
            <Text translate="true">Planlagt driftstid</Text>
        </translation>
        <current-translation>Temps de fonctionnement programmé</current-translation>
        <description>Label describing the number of hours a plant is scheduled to be in operation this year</description>
    </request>

    The parent being <translation> and the parent of the parent being <request>.  Finally, <description> being a child of <request>.  So you need to traverse up from <Text> through two parent nodes like this:

    ../../description

    or this

    parent::*/parent::*/description

    or this

    parent::translation/parent::request/description

    Writing this actually cements this understanding in my own head so it's a bit of self-therapy as well as hopefully being useful for others.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

    emoji