Link to home
Start Free TrialLog in
Avatar of metalmickey
metalmickey

asked on

ADDING ANOTHER XALAN OUTPUT FILE TO PROCESS

Hi Experts.

I've got a small xml file created and exported from an access database full of company vacancies.

Ive created and xslt that will transform the xml into html and i've managed to divide the contents of the xml file using xalan. Ive also created a secondary document which contains an anchored list of the files created which acts as a link page between them.

Heres my problem.

I also need to do is create another html file that is amost exaclty the same as the secondary file, which will again contain a list of the files generated and the secondary file, but without the majority of the html markup.

EG my XML contains 2 jobs and the output of the xalan will produce....

job1.html
job2.html
vacancies.html (which lists the 2 jobs and the relevant page styling)

what i need to additionally create is another file which contains the same list that is contained in vacancies.html, and the vacancy file itself so the new file will look like this.

<HTML>
<HEAD>
<TITLE>Which Weekly update file</TITLE>
</HEAD>
<BODY>

<A HREF="/recruitment/jobs/job1.html"></A>
<A HREF="/recruitment/jobs/job2.html"></A>
<A HREF="/recruitment/jobs/vacancies.html"></A>
</BODY>
</HTML>

Any idea where I can add this new instruction to my xslt?

My files are listed here

http://21stcenturyspace.co.uk/xalan/

 Transform.java        
 divide.jar              
 split.bat        
 transform.xsl
 vacancies.xml  


Thanks for any help you can give.

MM




Avatar of rdcpro
rdcpro
Flag of United States of America image

Not sure if I'm understanding your question, Metallic One, but you're looking to provide multiple output documents from one tranform, right?

If Xalan supports this module in EXSLT, then this might be a solution:

http://exslt.org/exsl/elements/document/index.html

Hmmm...looking closer, I see that only libxslt supports it as yet.

Oleg Tkachenko wrote an article some time back for MSDN that showed an approach to solve this in .NET.  I wonder if it could be leveraged and duplicated in java in your case.

Regards,
Mike Sharp
Avatar of metalmickey
metalmickey

ASKER

Hi Mike

The original article that chanced upon was here

http://www-106.ibm.com/developerworks/xml/library/x-tipdivbig/

the split.bat matches the xml and xslt and runs on via the j2sdk1.4.2_02.

all of the smart stuff is done on the desktop and the files are uploaded manually to a DB/CMS

ive got the multiple outputs, but need to add another.

MM

Isn't that just a matter of another template?  I haven't done it myself, but my understanding was you just add a template for each output, or at least a new xalan:redirect block within a single template.

Regards,
Mike Sharp
First: why not use separate XSLT for each output you want? write XSLT to output vacancies.html, 2nd XSLT for job1.html and so on?

Second: you can output some part of output document to anther file with Xalan, using

<redirect:write select="file_to_output">

it's declared in namespace:
xmlns:redirect="http://xml.apache.org/xalan/redirect"

See sample:
..............................
<xsl:template match="/doc/foo">
    <redirect:write select="file2.xml">
<!-- all processing called from this point wil be outputed to file2.xml -->

      <foo-out>
        <xsl:apply-templates/>
      </foo-out>
    </redirect:write>
  </xsl:template>
..............................

OK. You can combine this and mode parameter in <xsl:template> to write similiar processing for 2 cases that differs in some details and should be outputed to distinct files.

Does it what you want?
Do you need more samples?
Hi Dualsoul.

ive tried your method but i dont think ive got the template in the right place for an output.

to recap ive got 1 xslt. and one xml file

the default output from the xslt is the list (vacancies.html)

within the default template theres an apply templates instruction to build the separate (xalan:write) jobs pages.

now since i want to build the list again, ive duplicated the default template with in select="dataroot mode="weeklyupdates" with a xalan:write instruction.

For some reason this isnt being executed and therefore im getting no output for the new list.

Ive re-arraged the template below to show what im trying to do.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:gl="http://ananas.org/2003/tips/gallery" xmlns:xalan="org.apache.xalan.xslt.extensions.Redirect" extension-element-prefixes="xalan" xmlns:redirect="http://xml.apache.org/xalan/redirect">
      <xsl:output method="html"/>
      <!--   DEFAULT OUTPUT FOR THE XSLT     -->
            <xsl:template match="dataroot">
            <html>
                  <head>
                        <title/>
                  </head>
                  <body>
                        <span style="color:red;">To be uploaded to: /recruitment . Checkout from DYNA /recruitment/vacancies.html and save over with this file. Check recruitment/vacancies.html back in to DYNA</span>
                        <br clear="all"/>
                        <MAIN-CONTENT>
                              <H2>Jobs</H2>
                              <H3>Current job opportunities in London</H3>
                              <ul>
                                    <xsl:for-each select="Table1/Job_Number">
                                          <xsl:choose>
                                                <xsl:when test="preceding-sibling::Activate='1'">
                                                      <li>
                                                            <a>
                                                                  <xsl:attribute name="href">/recruitment/jobs/<xsl:value-of select="."/>.html</xsl:attribute>
                                                                  <xsl:attribute name="title"><xsl:value-of select="following-sibling::Job_Title"/></xsl:attribute>
                                                                  <xsl:value-of select="following-sibling::Job_Title"/>
                                                            </a>
                                                      </li>
                                                </xsl:when>
                                                <xsl:otherwise/>
                                          </xsl:choose>
                                    </xsl:for-each>
                              </ul>
                              <P>
Consumers' Association and Which? Limited are committed to an Equal Opportunities Policy to ensure that applicants are not discriminated against on the grounds of age, sex, ethnic origin, colour, disability or any other criteria.
</P>
                        </MAIN-CONTENT>
                  </body>
            </html>
            
                  <!--   APPLY THE SEPARATE OUTPUTS   -->
                  
            <xsl:apply-templates select="Table1"/>
            
                  <!--   APPLY THE DEFAULT OUTPUT AGAIN IN "WEEKLYUPDATES" MODE     -->
                  
            <xsl:apply-templates select="dataroot" mode="weeklyupdates"/>
      </xsl:template>
      
                  <!--   XALAN BUILD ALL THE SEPARATE JOB OUTPUTS     -->
      <xsl:template match="Table1">
            <xsl:variable name="job">
                  <xsl:value-of select="Job_Number"/>
            </xsl:variable>
            <xsl:choose>
                  <xsl:when test="child::Activate='1'">
                        <xalan:write select="concat($job,'.html')">
                              <html>
                                    <head>
                                          <title>Recruitment:</title>
                                    </head>
                                    <body>
                                          <span style="color:red;">To be uploaded to:  /recruitment/jobs and  apply template file:  /recruitment/templates/layout-job.html </span>
                                          <br clear="all"/>
                                          <MAIN-CONTENT>
                                                <DIV ID="JOB">
                                                      <xsl:if test="Activate='1'">
                                                            <xsl:apply-templates select="Job_Title"/>
                                                            <xsl:apply-templates select="Salary"/>
                                                            <xsl:apply-templates select="How_to_Apply"/>
                                                      </xsl:if>
                                                      <DIV ID="TOP">
                                                            <A HREF="#top">top</A>
                                                      </DIV>
                                                </DIV>
                                                <BR CLEAR="ALL"/>
                                          </MAIN-CONTENT>
                                    </body>
                              </html>
                        </xalan:write>
                  </xsl:when>
                  <xsl:otherwise/>
            </xsl:choose>
      </xsl:template>
      
      <!-- WEEKLYUPDATES MODE  -->
      
      <xsl:template match="dataroot" mode="weeklyupdates">
            <xalan:write select="weeklyupdates.html">
                  <html>
                        <head>
                              <title/>
                        </head>
                        <body>
                              <xsl:for-each select="Table1/Job_Number">
                                    <xsl:choose>
                                          <xsl:when test="preceding-sibling::Activate='1'">
                                                <a>
                                                      <xsl:attribute name="href">/recruitment/jobs/<xsl:value-of select="."/>.html</xsl:attribute>
                                                </a>
                                          </xsl:when>
                                          <xsl:otherwise/>
                                    </xsl:choose>
                              </xsl:for-each>
                        </body>
                  </html>
            </xalan:write>
      </xsl:template>

      <!-- OTHER FORMATTING ONLY TEMPLATES BELOW  -->
      
      <xsl:template match="Job_Title">
            <H2>
                  <xsl:value-of select="."/>
            </H2>
      </xsl:template>
      <xsl:template match="Salary">
            <DIV ID="PAY">
                  <H3>
                        <xsl:value-of select="."/>
                  </H3>
                  <xsl:variable name="vDate" select="normalize-space(following-sibling::Closing_Date)"/>
                  <xsl:variable name="vYear" select="substring($vDate, 1, 4)"/>
                  <xsl:variable name="vMonth" select="substring($vDate, 6, 2)"/>
                  <xsl:variable name="vDay" select="substring($vDate, 9, 2)"/>
                  <P>
                        <STRONG>Closing date:
      <xsl:value-of select="$vDay"/>
                              <xsl:choose>
                                    <xsl:when test="$vMonth ='01'"> January </xsl:when>
                                    <xsl:when test="$vMonth ='02'"> February </xsl:when>
                                    <xsl:when test="$vMonth ='03'"> March </xsl:when>
                                    <xsl:when test="$vMonth ='04'"> April </xsl:when>
                                    <xsl:when test="$vMonth ='05'"> May </xsl:when>
                                    <xsl:when test="$vMonth ='06'"> June </xsl:when>
                                    <xsl:when test="$vMonth ='07'"> July </xsl:when>
                                    <xsl:when test="$vMonth ='08'"> August </xsl:when>
                                    <xsl:when test="$vMonth ='09'"> September </xsl:when>
                                    <xsl:when test="$vMonth ='10'"> October </xsl:when>
                                    <xsl:when test="$vMonth ='11'"> November </xsl:when>
                                    <xsl:when test="$vMonth ='12'"> December </xsl:when>
                              </xsl:choose>
                              <xsl:value-of select="$vYear"/>
                        </STRONG>
                  </P>
                  <xsl:apply-templates select="following-sibling::Job_Para_1"/>
                  <xsl:apply-templates select="following-sibling::Job_Para_2"/>
                  <xsl:apply-templates select="following-sibling::Job_Para_3"/>
                  <xsl:apply-templates select="following-sibling::Job_Para_4"/>
                  <DIV ID="TOP">
                        <A HREF="#top">top</A>
                  </DIV>
                  <BR CLEAR="ALL"/>
                  <H3>Job Aim</H3>
                  <xsl:apply-templates select="following-sibling::Job_Aim_1"/>
                  <xsl:apply-templates select="following-sibling::Job_Aim_2"/>
                  <xsl:apply-templates select="following-sibling::Job_Aim_3"/>
                  <xsl:apply-templates select="following-sibling::Job_Aim_4"/>
                  <br clear="all"/>
                  <H3>Main Duties</H3>
                  <ul>
                        <xsl:apply-templates select="following-sibling::Duty1"/>
                        <xsl:apply-templates select="following-sibling::Duty2"/>
                        <xsl:apply-templates select="following-sibling::Duty3"/>
                        <xsl:apply-templates select="following-sibling::Duty4"/>
                        <xsl:apply-templates select="following-sibling::Duty5"/>
                        <xsl:apply-templates select="following-sibling::Duty6"/>
                        <xsl:apply-templates select="following-sibling::Duty7"/>
                        <xsl:apply-templates select="following-sibling::Duty8"/>
                        <xsl:apply-templates select="following-sibling::Duty9"/>
                        <xsl:apply-templates select="following-sibling::Duty10"/>
                        <xsl:apply-templates select="following-sibling::Duty11"/>
                        <xsl:apply-templates select="following-sibling::Duty12"/>
                        <xsl:apply-templates select="following-sibling::Duty13"/>
                        <xsl:apply-templates select="following-sibling::Duty14"/>
                  </ul>
                  <H3>Additional recruitment requirements</H3>
                  <ul>
                        <xsl:apply-templates select="following-sibling::Additional_Reqs1"/>
                        <xsl:apply-templates select="following-sibling::Additional_Reqs2"/>
                        <xsl:apply-templates select="following-sibling::Additional_Reqs3"/>
                        <xsl:apply-templates select="following-sibling::Additional_Reqs4"/>
                        <xsl:apply-templates select="following-sibling::Additional_Reqs5"/>
                        <xsl:apply-templates select="following-sibling::Additional_Reqs6"/>
                  </ul>
                  <DIV ID="TOP">
                        <A HREF="#top">top</A>
                  </DIV>
                  <BR CLEAR="ALL"/>
            </DIV>
      </xsl:template>
      <xsl:template match="Closing_Date"/>
      <xsl:template match="How_to_Apply">
            <DIV ID="APPLY">
                  <xsl:variable name="num" select="preceding-sibling::Job_Number"/>
                  <xsl:variable name="tit" select="preceding-sibling::Job_Title"/>
                  <H3>How To Apply</H3>
                  <P>
To apply, use our <a href="/recruitment/apply.html">online application form</a> or send your CV and cover letter, quoting <xsl:value-of select="$num"/>, to:
<A HREF="mailto:recruitment@which.co.uk?subject=i{$num} - {$tit}">recruitment@which.co.uk</A>, or to,</P>
                  <DIV CLASS="add">
Human Resources Department<BR/>
Consumers' Association<BR/>
2 Marylebone Road<BR/>
London NW1 4DF.<BR clear="all"/>
                  </DIV>
                  <br clear="all"/>
                  <H3>Email this page to a friend</H3>
                  <FORM NAME="send" METHOD="POST" ACTION="/cgi-bin/sendPageLink.pl">
                        <label for="Your name">Your name</label>
                        <INPUT NAME="name" TYPE="TEXT"/>
                        <br clear="all"/>
                        <label for="Friends_email">Friends email address:</label>
                        <INPUT NAME="friends_email" TYPE="TEXT"/>
                        <br clear="all"/>
                        <INPUT TYPE="SUBMIT" VALUE="Send"/>
                  </FORM>
            </DIV>
      </xsl:template>
      <xsl:template match="*[contains(local-name(),'Job_Para_')]">
            <p>
                  <xsl:value-of select="."/>
            </p>
      </xsl:template>
      <xsl:template match="*[contains(local-name(),'Job_Aim')]">
            <p>
                  <xsl:value-of select="."/>
            </p>
      </xsl:template>
      <xsl:template match="*[contains(local-name(),'Duty')]">
            <li>
                  <xsl:value-of select="."/>
            </li>
      </xsl:template>
      <xsl:template match="*[contains(local-name(),'Additional')]">
            <li>
                  <xsl:value-of select="."/>
            </li>
      </xsl:template>
      
</xsl:stylesheet>



Hope you can shed a little more light on the problem

MM
Hi metalmickey.

I doesn't see your sample XML. Please post it, so i can check your XSLT and do something with it :)
http://21stcenturyspace.co.uk/xalan/vacancies.xml

its posted here if youve got time to look at it.

Theres 5 entries in it so far.


thanks again.

MM
ASKER CERTIFIED SOLUTION
Avatar of dualsoul
dualsoul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Dualsoul thats great,

Thanks for taking the time out to look at the xsl. Id never have found those errors!

MM

you are welcome :)