Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL Question

Status
Not open for further replies.

Dynapen

Programmer
Apr 20, 2000
245
US
Here's what I have.

Receving applications. Each XML file will contain multiple applications for the same person. Each Application can contain multiple
XML file will look something like.

Code:
<application>
  <event>
    <event_code>1</event_code>
    <event_desc>Rejected</event_desc>
    <reason_code>1</reason_code>
    <reason_desc>Missing Name</reason_desc>
  </event>
  <event>
    <event_code>1</event_code>
    <event_desc>Rejected</event_desc>
    <reason_code>2</reason_code>
    <reason_desc>Missing Address</reason_desc>
  </event>
  <event>
    <event_code>1</event_code>
    <event_desc>Rejected</event_desc>
    <reason_code>3</reason_code>
    <reason_desc>Missing Phone</reason_desc>
  </event>
  <event>
    <event_code>1</event_code>
    <event_desc>Rejected</event_desc>
    <reason_code>4</reason_code>
    <reason_desc>Missing State</reason_desc>
  </event>
  <event>
    <event_code>2</event_code>
    <event_desc>Received</event_desc>
    <reason_code>000</reason_code>
    <reason_desc>None</reason_desc>
  </event>
</application>

Unfortunately I can't change this much becuase of the feed we are getting from the source. A single event can have multiple reason codes, but I in the DB they will be stored in the same row with the event code being duplicated, while the reason code will be unique. (They will be selected by the app ID, which will be unique but that's higher up the chain).


What I need to do is make a display like

ApplicationID AppDate Time
EventCode EventDesc Date Time
ReasonCode ReasonDesc
ReasonCode ReasonDesc
ReasonCode ReasonDesc
EventCode EventDesc Date Time


I have looked at doing the xsl:apply-templates option, but it will iterate over a template identified by a element. I don't know how to get it to realize that subsequenct iterations over the same event (same event code and app ID) need to be displayed differently.

Any ideas?




 
Hope this helps.
I added an application_id node, to test with more than applicication
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
   <xsl:output method="html" encoding="Windows-1252" />

   <xsl:template match="/">
      <html>
         <body>
            <xsl:apply-templates select="//application" />
         </body>
      </html>
   </xsl:template>

   <xsl:template match="application">
<!-- print application details -->
      <h1>
         <xsl:value-of select="application_id" />
      </h1>

<!-- only match those events with code -->
<!-- that is not the code of a preceding event in same application -->
      <xsl:apply-templates select="event[not(event_code = preceding-sibling::event/event_code)]" mode="general" />
   </xsl:template>

   <xsl:template match="event" mode="general">
<!-- print event details that are the same for all event-nodes with the same event_code -->
      <h2>
         <xsl:value-of select="event_code" />

         <xsl:value-of select="event_desc" />
      </h2>

<!-- match all events in this application with the same event_code as the current one -->
      <xsl:apply-templates select="../event[event_code=current()/event_code]" mode="unique" />
   </xsl:template>

   <xsl:template match="event" mode="unique">
<!-- print event details that are unique for each event-node -->
      <p>
         <xsl:value-of select="reason_code" />

         <xsl:value-of select="reason_desc" />
      </p>
   </xsl:template>
</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top