Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1073
  • Last Modified:

XSLT/XPATH - link ancestor node value

Code of interest:
<xsl:for-each select="//WebformData/Itlist/Dilist[Fitemn=ancester::Fitemn*]" order-by="@SeqNo">

In my code sample, I am trying to make the above line of code to associate between the //WebformData/Itlist/Fitemn  and  //WebformData/Itlist/Dilist/Fitemn
There is a one to many relationship between //WebformData/Itlist and  //WebformData/Itlist/Dilist with the Fitemn being the link.

When I substitute the following code, the data shows up correctly
<xsl:for-each select="//WebformData/Itlist/Dilist[Fitemn=1]" order-by="@SeqNo">
The following code also works
<xsl:for-each select="//WebformData/Itlist/Dilist[Fitemn=2]" order-by="@SeqNo">

So, it looks like what I need is the code that properly references the ancestor Fitemn node with the self Fitemn node.

Thanks for any help.  I am learning XSLT and XPATH and very stuck!

Keith
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="JavaScript">
<xsl:script>
 
function spaces(number)
{
        var string = "";
        var blank = " ";
        while (string.length &lt; number)
        {
                string = string + blank;
        }
        return string;
}
 
function PadString(value, number)
{
        var string = "";
        var blank = " ";
        
        if (value.text.length > 0)
           string = value.text;
           
        while (string.length &lt; number)
        {
                string = string + blank;
        }
        
        return string;          
}
 
function PadNumeric(value, number)
{
        var string = "";
        var blank = " ";
        
        if (value.text.length > 0)
           string = value.text;
           
        while (string.length &lt; number)
        {
                string = blank + string;
        }
        
        return string;          
}
 
</xsl:script>
<xsl:template match="/">
<table border="1">
<tr><th>PR#</th><th>SEC CODE</th></tr>
<tr><td>
<xsl:for-each select="xml/user_vars/pr"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/seccd"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
</tr>
</table>
 
<table border="1">
<tr><td>Is this a purchase of goods/materials</td>
<td>
<xsl:for-each select="xml/user_vars/puryn"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
</tr><tr>
<td></td>
<td>
<xsl:for-each select="xml/user_vars/qtyyn"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
</tr>
<tr>
<td>Is this a service agreement or a contract?</td>
<td>
<xsl:for-each select="xml/user_vars/agryn"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
</tr>
<tr>
<td>
Is insurance on file?
</td>
<td>
<xsl:for-each select="xml/user_vars/propyn"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
</tr>
 
<tr>
<td>Is there a proposalNoYes
</td>
<td>
<xsl:for-each select="xml/user_vars/insyn"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
 
</tr>
 
</table>
   
<table border="1">
<tr><th>DATE REQUESTED</th><th>END USE/DEPT</th><th>ENTERED BY</th><th>ENTER DATE </th></tr>
<tr>
<td>
<xsl:for-each select="xml/user_vars/reqdt"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/enduse"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/entby"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/entdt"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
</tr>
</table>
<table border="1">
<tr><th>DATE EXPECTED</th><th>DATE REQUIRED</th><th>DELIVERY DATE</th><th>EXPIRATION DATE </th></tr>
<tr>
<td>
<xsl:for-each select="xml/user_vars/expdt"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/reddt"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/deldt"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/exprdt"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
</tr>
</table>
   
 
<table border="1">
<tr><th>VENDOR ID</th><th>VENDOR NAME</th><th>VEN ADDR CD</th><th>VENDOR ADDRESS  </th></tr>
<tr>
<td>
<xsl:for-each select="xml/user_vars/venid"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/vennam"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
<xsl:for-each select="xml/user_vars/venph"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
<xsl:for-each select="xml/user_vars/venfx"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/vencd"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="xml/user_vars/venad"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each>
</td>
</tr>
</table>
 
 
<table border="1">
<tr><th>Item</th><th>Qty</th><th>Amt</th><th>Unit</th><th>Tax Cd</th><th>Ext Amt</th><th>Desc</th><th>Key</th><th>Obj</th></tr>
 
<xsl:for-each select="//WebformData/Itlist" order-by="@SeqNo">
 
<tr>
<td valign="top">
<xsl:for-each select="Fitemn"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each></td>
<td valign="top">
<xsl:for-each select="Fquant"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each></td>
<td valign="top">
<xsl:for-each select="Festam"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each></td>
<td valign="top">
<xsl:for-each select="Funit"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each></td>
<td valign="top">
<xsl:for-each select="Ftaxcd"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each></td>
<td valign="top">
<xsl:for-each select="Fextpr"><xsl:value-of select="."></xsl:value-of></xsl:for-each>
</td>
<td valign="top">
<xsl:for-each select="Fdescr"><xsl:value-of select="."></xsl:value-of><table>
<xsl:for-each select="//WebformData/Itlist/Dilist[Fitemn=ancester::Fitemn*]" order-by="@SeqNo"><tr>
<td><xsl:for-each select="Fperc"><xsl:value-of select="."></xsl:value-of></xsl:for-each></td>
<td><xsl:for-each select="Fobjcd"><xsl:value-of select="."></xsl:value-of></xsl:for-each></td>
<td><xsl:for-each select="Forgky"><xsl:value-of select="."></xsl:value-of></xsl:for-each></td>
</tr></xsl:for-each></table>
</xsl:for-each>
</td>
<td valign="top">
<xsl:for-each select="Forgky"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each></td>
<td valign="top">
<xsl:for-each select="Fobjcd"><xsl:value-of select="."></xsl:value-of>
</xsl:for-each></td>
</tr>
 
</xsl:for-each>
</table>
 
 
 
 
</xsl:template>
</xsl:stylesheet>

Open in new window

0
KeithMcElroy
Asked:
KeithMcElroy
  • 5
  • 3
  • 2
1 Solution
 
KeithMcElroyAuthor Commented:
Here is a sample of the xml
- <xml>
- <LastLog>
- <Log>
  <Entry Level="8" Type="W" ID="Main Flow">Start</Entry> 
  <Entry Level="4" Type="T" ID="T4" Result="-1" /> 
  <Entry Level="4" Type="A" ID="A1">Transition T4 is true</Entry> 
  <Entry Level="4" Type="A" ID="A1" Result="-1">At least one Transition is active</Entry> 
  <Entry Level="4" Type="A" ID="A1" Result="2">Execute Results</Entry> 
  <Entry Level="4" Type="A" ID="A4" Result="5">Activity in Future Transition</Entry> 
  </Log>
  </LastLog>
- <WebformData>
- <Itlist SeqNo="1">
  <Fitemn>1</Fitemn> 
  <Fquant>100</Fquant> 
  <Festam>100</Festam> 
  <Funit>BOX</Funit> 
  <Ftaxcd>7.25</Ftaxcd> 
  <Fextpr>10725.00</Fextpr> 
  <Fdescr>PENCILS</Fdescr> 
  <Forgky>03321</Forgky> 
  <Fobjcd>5011</Fobjcd> 
  <Fpronu /> 
  <Factcd /> 
- <Dilist SeqNo="1">
  <Fdistn>1</Fdistn> 
  <Fitemn>1</Fitemn> 
  <Forgky>03321</Forgky> 
  <Facct /> 
  <Fproj /> 
  <Fobjcd>5011</Fobjcd> 
  <Fperc>90</Fperc> 
  <Famt>10000</Famt> 
  </Dilist>
- <Dilist SeqNo="2">
  <Fdistn>2</Fdistn> 
  <Fitemn>1</Fitemn> 
  <Forgky>00503</Forgky> 
  <Facct /> 
  <Fproj /> 
  <Fobjcd>1200</Fobjcd> 
  <Fperc>10</Fperc> 
  <Famt>725</Famt> 
  </Dilist>
  </Itlist>
- <Itlist SeqNo="2">
  <Fitemn>2</Fitemn> 
  <Fquant>100</Fquant> 
  <Festam>100</Festam> 
  <Funit>BOX</Funit> 
  <Ftaxcd>7.25</Ftaxcd> 
  <Fextpr>10725.00</Fextpr> 
  <Fdescr>RULERS</Fdescr> 
  <Forgky>03321</Forgky> 
  <Fobjcd>5011</Fobjcd> 
  <Fpronu /> 
  <Factcd /> 
- <Dilist SeqNo="1">
  <Fdistn>1</Fdistn> 
  <Fitemn>2</Fitemn> 
  <Forgky>03321</Forgky> 
  <Facct /> 
  <Fproj /> 
  <Fobjcd>5011</Fobjcd> 
  <Fperc>80</Fperc> 
  <Famt>9000</Famt> 
  </Dilist>
- <Dilist SeqNo="2">
  <Fdistn>2</Fdistn> 
  <Fitemn>2</Fitemn> 
  <Forgky>00503</Forgky> 
  <Facct /> 
  <Fproj /> 
  <Fobjcd>1200</Fobjcd> 
  <Fperc>20</Fperc> 
  <Famt>1725</Famt> 
  </Dilist>
  </Itlist>
  </WebformData>
- <user_vars>
  <agryn>No</agryn> 
  <appcd /> 
  <appdt /> 
  <appr1 /> 
  <appr2 /> 
  <appr3 /> 
  <comments>03321 501100503 1200</comments> 
  <comments_1 /> 
  <deldt>7/1/2008</deldt> 
  <divis /> 
  <enduse>TEST END USE</enduse> 
  <entby>BSI</entby> 
  <estup /> 
  <expdt>7/1/2008</expdt> 
  <exprdt /> 
  <insyn>No</insyn> 
  <next /> 
  <ponum /> 
  <pr>TEST0617</pr> 
  <propyn>No</propyn> 
  <puryn>No</puryn> 
  <qtyn /> 
  <reddt>7/1/2008</reddt> 
  <req /> 
  <reqdt>7/1/2008</reqdt> 
  <reqnm>KEITH TESTING</reqnm> 
  <reqno /> 
  <seccd>@@</seccd> 
  <venad>P O BOX 99023</venad> 
  <venaddc /> 
  <vencd>R1</vencd> 
  <venid>V01223</venid> 
  <vennam>my vendor</vennam> 
  <verif /> 
  </user_vars>
  <OldData /> 
  </xml>

Open in new window

0
 
Geert BormansCommented:
You are using an old working draft of XSLT, that is only supported by microsoft, and that has been dropped 10 years ago
xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
you should use real XSLT instead
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

I think what you want to do is this
<xsl:for-each select="//WebformData/Itlist/Dilist[Fitemn = ancestor::Itlist/Fitemn]" order-by="@SeqNo">
0
 
KeithMcElroyAuthor Commented:
1.  I switched to the suggested XSLT first without any other modifications.
Result:  Style sheet does not work.  
Note: This is a financial application that was built approximately 1998-2000.  That would explain why it is so old.

2.  I dropped in the new XPATH with ancestor code, both with and without #1 above.
Result: Style sheet does not work, with old or new XSLT.

Any ideas on next steps?  Is the XPATH ancestor code dependent on #1 above?
Are there any ideas on why the application is tied to the older XSLT?

Thank you for all the help,
Keith

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Geert BormansCommented:
It could well be that ancestor was not supported in the working draft, I don't remember.
You could try to make this a variable and compare to the variable...
but I am very unaware of Working Draft syntax for that

I used the working draft only because it was the first XSLT implementation.
I threw it out of the window asap when the real thing arrived :-)
0
 
jkmyoungCommented:
Instead of using <xsl:script> elements (which I think are deprecated), I suggest writing the javascript in the header like so:

<xsl:template match="/">
<script type="text/javascript">
.... contents of <xsl:script> elements. ...
</script>
rest of your xsl
0
 
KeithMcElroyAuthor Commented:
jkmyoung:  OK, I think I understand. Actually, I think I can get rid of the javascript.  It was a copy over from another page and I believe does not apply in this page.  Is your thought that the javascript was the point of failure with the newer XLS and that I will be able to use the newer XLS (after dropping the javascript which is deprecated) and thus use the ancestor solution?  I will try this and advise.  Thank you!
Keith
0
 
KeithMcElroyAuthor Commented:
Did not work.  I stripped out the javascript and replaced the declaration.
Any alternatives?  
0
 
KeithMcElroyAuthor Commented:
<xsl:for-each select="//WebformData/Itlist/Dilist[Fitemn = //WebformData/Itlist/Fitemn]" order-by="@SeqNo"><tr>

Is there a way to make this statement reference the current node?
0
 
Geert BormansCommented:
would this not work?
<xsl:for-each select="//WebformData/Itlist/Dilist[Fitemn = current()/Fitemn]" order-by="@SeqNo"><tr>

though I am afraid current() is not supported in Working Draft either
0
 
jkmyoungCommented:
To avoid using current, you create a variable to the Fitemn value, and use it in your for each.
Eg, depending on context:
<xsl:variable name="Fitemn" select="Fitemn"/>
<xsl:for-each select="//WebformData/Itlist/Dilist[Fitemn = $Fitemn]">

or perhaps:

<xsl:for-each select="//WebformData/Itlist">
  <xsl:variable name="Fitemn" select="Fitemn"/>
  <xsl:for-each select="Dilist[Fitemn = $Fitemn]">
   ......
  </xsl:for-each>
</xsl:for-each>

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now