Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2004, 03:54 PM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL processing question..

I have an xml file that looks like this (vaguely):

<AppvInvDoc>
  <AppvInv ActionCode="U">
    <AH>
      stuff...
    </AH>
    <AL>
      more stuff...
      <AD>
        still more stuff
      </AD>
      <AD>
        still more stuff
      </AD>
    </AL>
    <AL>
      more stuff
      <AD>
        still more stuff
      </AD>
    </AL>
  </AppvInv>
</AppvInvDoc>

I have to use an XSLT to turn this into a flat file. The example above should result in three different lines. For each AD that's processed, I need access to it's parent AL element, and the AH element at the top.

What's the right witches brew of matches, for-eaches and so forth? I've been playing with this for about a day and I can't wrap my head around the answer.

Thanks,

Eric

 
Old August 24th, 2004, 07:58 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm afraid it's going to be difficult to be more specific without knowing exactly what you want to get from accessing each of these nodes, but in general:

<xsl:template match="/">
    <xsl:apply-templates select="//AD" />
</xsl:template>

<xsl:template match="/">
    do stuff here
</xsl:template>

will match each of your AD nodes.

Using select="parent::*" within the AD template will select the parent node of the current AD node you are processing.

If you only ever have one AH node then you can always access it with simply //AH (or the full path - i'm just being lazy here).
Personally I wouldn't mix text and elements within a node i.e.

<elem>
   some text
   <an_elem />
</elem>

because it is a pain it the buttski to separate the text later. Depending on the size of the text, consider using an attribute; something like:

<elem some_text="put your text here">
  <an_elem />
</elem>

You can get this out later using select="elem@some_text"

Or putting a different named node above the AD nodes.

I hope that's helpful.

hmk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional processing in XSL francislang XSLT 2 March 18th, 2008 12:04 AM
xsl question bluisana XSLT 7 September 15th, 2005 01:34 AM
xsl:sort Question kwilliams XSLT 6 July 18th, 2005 08:39 AM
xsl:if question rdavisiii XSLT 2 March 30th, 2005 01:40 PM
Create processing instruction in XSL hbcontract XML 6 May 7th, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.