[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: Re: [xsl] Newbie - trying to extract specific values from XML file.


Subject: RE: Re: [xsl] Newbie - trying to extract specific values from XML file.
From: cknell@xxxxxxxxxx
Date: Fri, 19 Mar 2004 12:29:05 -0500

My browser won't show me the source of your HTML file and I don't have time to debug it today. I do have some thoughts on your problem. Now that I see the application, my first approach will have to be modified.

I think I would put all my code in the template that matches the root:

<xsl:output method="html" indent="yes" encoding="UTF-8" />
<xsl:template match="/">
   <html>
      <body>
        <xsl:choose>
          <xsl:when test="AnswerSet/Answer[name='1. Restriction &amp; Conditions'][TFValue='false']">
            &lt;-- suppose you need to get the value from another "Answer" element to insert here--&gt;
            <xsl:value-of select="AnswerSet/Answer[@name='Instructions']/RptValue/DateValue" />
          </xsl:when>
          <xsl:when test="AnswerSet/Answer[name='1. Restriction &amp; Conditions'][TFValue='true']">
            &lt;-- Your alternate HTML here --&gt;
          </xsl:when>        
        </xsl:choose>
      </body>
   </html>
</xsl:template>

It would involve a large number of <xsl:choose> elements with XPath predicates (the part of the test inside the []) to select the values you want to consider. Your XML document is not highly structured (only three element names inside the <AnswerSet> root element and the nesting isn't very deep). This means that the XPath tests will not be overly lengthly, but it makes the preferred "push" model approach impractical so you'll have to use the "pull" model.

By putting all the code in the root template you make it very large, so you'll have to be careful not to get lost. On the other hand, by putting all the code in the root template, you fix your context so all XPath expressions start at the same place.
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Julian Voelcker <asp@xxxxxxx>
Sent:     Fri, 19 Mar 2004 16:18:45 GMT
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Re: [xsl] Newbie - trying to extract specific values from XML  file.

Hi Charles,

> Your description is very light on details and of a general nature, so in a general way, yes, it makes sense.

OK, to provide you with a bit more info...

I have a long html file (see http://hq.tvw.net/template.html) that includes a mass of merge codes from an old program.

The merge codes are encompassed in « » delimiters.

The source data is in the format already described (see http://hq.tvw.net/sourcedata.xml for the full file - note it includes quite a few irrelevant answers that are ignored (e.g. 1. Restriction & Conditions))

Rather than write my own mail merge engine or use a 3rd party product someone has suggested that I can do the same sort of thing using XSL.

I am therefore considering creating an XSL template to recreate the html file but replacing the old merge codes with XSL logic.

OK, there is a little bit more than that, but it should give you a better idea of what I am trying to do.

-- 
Cheers,

Julian Voelcker
United Kingdom



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords