Search code examples
xmlxsltxsl-foaltova

Get a value from a XML in XSL document version 1.0


I have one problem. I am writing a table in a PDF document. I am getting all the right values except one.

I get a value from a XML lets call that for example Then I need to find that name in the same XML document and take another value from the other place where it appears:

Look at this example XML document:

               </Comment>
                   (...)




                  <Comment>
                  </Comment>

So I am writing the NAME inside

Need to save that value, find it in Tset node and write the ToolAddr value after the State, Program name and Tool Name in xsl code.

My xsl to show the NAME and want the next cell to show the size finding by the name:

I need this because Tset is a list of all tools, and in Machining i use the tools not for the normal order and may need the tool adress of the tool more than one time...

HELP!!!


Solution

  • Because the question is a bit vague, it is hard to give a precise answer, but it sounds like you could do with using an xsl:key to look up the value (or values) you want.

    If you want to look up code elements but their product/Name you could define a key like so:

    <xsl:key name="lookupcode" match="code" use="following-sibling::product[1]/Name" />
    

    So, this matches code elements, but allows them to be looked up by the "Name" of first Product element that follows it. (Note, if you are actually using namespaces, rememeber to put the relevant prefix before xxx).

    Then, for example, to use this key to look up the code of the 'asdf' value, you would do this

    <xsl:value-of select="key('lookupcode', 'asdf')" />
    

    In a slightly more practical example, if you wanted to look up the code for the NAME elements under zzz, your code might look something like this:

    <xsl:for-each select="zzz/NAME">
        Name: <xsl:value-of select="." />
        code: <xsl:value-of select="key('lookupcode', .)" />
    </xsl:for-each>
    

    In a slighty more practical example, here is a simple example that outputs an HTML table.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output omit-xml-declaration="yes" indent="yes" />
    
       <xsl:key name="lookupcode" match="code" use="following-sibling::product[1]/Name" />
    
       <xsl:template match="yyyy">
          <table>
             <xsl:for-each select="zzz/Name">
                <tr> 
                   <td><xsl:value-of select="." /></td>
                   <td><xsl:value-of select="following-sibling::DATE[1]" /></td>
                   <td><xsl:value-of select="key('lookupcode', .)" /></td>
                </tr>
             </xsl:for-each>
          </table>
       </xsl:template>
    </xsl:stylesheet>
    

    This should be easy enough to convert to output xsl:fo instead. "tr" elements correspond to "fo:table-row" and "td" elements correspond to "fo:table-cell".