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 May 21st, 2011, 03:31 AM
Registered User
 
Join Date: May 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default [Urgent]How to exit for each loop in XSLT

Hi,
I am trying to convert a word xml into another xml file format using XSLT.
Here I need to check the all the following siblings with some condition. If that condition is satisfied, the control should exit from that loop.

How can i achieve this, I am desperately need this. Plz Help Any one...

Thanks in Advance..

Regards
Sudheer
 
Old May 21st, 2011, 04:02 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Your are thinking in a procedural manner, which is wrong. XSLT is a functional language.

Without some more specific details we can't really help, but you need to change your thinking.

Rather than this:

for each item in list
if condition true then exit
do something
next item

You need to think like this:

for each item in list where condition not true
do something
next item

If you supply a sample XML input, and what you want to output, and whatever you have so far for your XSLT then we will be able to help more.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
sudheer2250 (May 21st, 2011)
 
Old May 21st, 2011, 05:14 AM
Registered User
 
Join Date: May 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default There are the Complete Specifiacations...

My actual task is to convert a word Document containing Tables into specific XML Format. So what i have done is, first saved the word doc as word 2003 xml format. That is the input file for XSLT here.
Input XML:
http://wikisend.com/download/264974/Input.xml

Developed XSLT So far is :
http://wikisend.com/download/265092/Developed XSLT.xslt

And this is the XML format I need to covert the Input XML file.
http://wikisend.com/download/265034/Target Format.xml


Here In order put the Subquestion inside the correspoing Question, I want to do the For-each in "FollowingSiblings".
 
Old May 21st, 2011, 08:38 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No-one is going to even bother to look at a 1.3MB wordML file and attempt to work out what you are trying to do. Its the kind of thing you only ever do if you're being paid to do it.

Try writing a 'sample' input XML, showing the elements you are bothered about, and the output you want to generate.

Sam
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
sudheer2250 (May 21st, 2011)
 
Old May 21st, 2011, 09:38 AM
Registered User
 
Join Date: May 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default These is the sample code what i am doing....

2.PERSONNEL YES NO N/A
a. Are there sufficient maintenance personnel to safely maintain company aircraft at primary facility and en route locations?
b. Does the new-hire process provide for:
(1) Sufficient background check?
(2) Drug and alcohol abuse testing?
c. Does the carrier experience a great deal of turnover?
d. Are the carrier’s maintenance employee’s union members?
(1) When is the contract up for renegotiations and are any
problems expected?
(2) What is the quality of the relationship between management
and the union?

This the Table in a Word Document (Screen Shot here: http://wikisend.com/download/298068/Untitled.png). When i save the word doc as word xml 2003 format, it will generate the following xml file.

This is the Input XML:( I tried to minimise it ASAP, but it is auto generated)

<w:tbl>
<w:tr wsp:rsidR="00E77079" wsp:rsidRPr="00E7149E" wsp:rsidTr="00B51904">
<w:tc>
<w:tcPr>
<w:tcW w:w="3852" w:type="pct"/>
<w:shd w:val="clear" w:color="auto" w:fill="auto"/>
</w:tcPr>
<w:p wsp:rsidR="00E77079" wsp:rsidRPr="00221D14" wsp:rsidRDefault="00E77079" wsp:rsidP="00040FAA">
<w:pPr>
<w:tabs>
<w:tab w:val="left" w:pos="360"/>
<w:tab w:val="left" w:pos="720"/>
<w:tab w:val="left" w:pos="1080"/>
</w:tabs>
<w:rPr>
<w:b/>
<w:color w:val="000000"/>
</w:rPr>
</w:pPr>
<w:r wsp:rsidRPr="00221D14">
<w:rPr>
<w:color w:val="000000"/>
</w:rPr>
<w:br w:type="column"/>
</w:r>
<w:r>
<w:rPr>
<w:b/>
<w:b-cs/>
<w:color w:val="0000A0"/>
</w:rPr>
<w:t>2.</w:t>
</w:r>
<w:r wsp:rsidRPr="00221D14">
<w:rPr>
<w:b/>
<w:b-cs/>
<w:color w:val="0000A0"/>
</w:rPr>
<w:t>PERSONNEL</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="384" w:type="pct"/>
<w:shd w:val="clear" w:color="auto" w:fill="auto"/>
</w:tcPr>
<w:p wsp:rsidR="00E77079" wsp:rsidRPr="00221D14" wsp:rsidRDefault="00E77079" wsp:rsidP="00040FAA">
<w:pPr>
<w:tabs>
<w:tab w:val="left" w:pos="360"/>
<w:tab w:val="left" w:pos="720"/>
<w:tab w:val="left" w:pos="1080"/>
</w:tabs>
<w:spacing w:before="100" w:before-autospacing="on" w:after="100" w:after-autospacing="on"/>
<w:jc w:val="center"/>
<w:rPr>
<w:color w:val="000000"/>
</w:rPr>
</w:pPr>
<w:r wsp:rsidRPr="00221D14">
<w:rPr>
<w:b-cs/>
<w:color w:val="0000A0"/>
</w:rPr>
<w:t>YES</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="384" w:type="pct"/>
<w:shd w:val="clear" w:color="auto" w:fill="auto"/>
</w:tcPr>
<w:p wsp:rsidR="00E77079" wsp:rsidRPr="00221D14" wsp:rsidRDefault="00E77079" wsp:rsidP="00040FAA">
<w:pPr>
<w:tabs>
<w:tab w:val="left" w:pos="360"/>
<w:tab w:val="left" w:pos="720"/>
<w:tab w:val="left" w:pos="1080"/>
</w:tabs>
<w:spacing w:before="100" w:before-autospacing="on" w:after="100" w:after-autospacing="on"/>
<w:jc w:val="center"/>
<w:rPr>
<w:color w:val="000000"/>
</w:rPr>
</w:pPr>
<w:r wsp:rsidRPr="00221D14">
<w:rPr>
<w:b-cs/>
<w:color w:val="0000A0"/>
</w:rPr>
<w:t>NO</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="381" w:type="pct"/>
<w:shd w:val="clear" w:color="auto" w:fill="auto"/>
</w:tcPr>
<w:p wsp:rsidR="00E77079" wsp:rsidRPr="00221D14" wsp:rsidRDefault="00E77079" wsp:rsidP="00040FAA">
<w:pPr>
<w:tabs>
<w:tab w:val="left" w:pos="360"/>
<w:tab w:val="left" w:pos="720"/>
<w:tab w:val="left" w:pos="1080"/>
</w:tabs>
<w:spacing w:before="100" w:before-autospacing="on" w:after="100" w:after-autospacing="on"/>
<w:jc w:val="center"/>
<w:rPr>
<w:color w:val="000000"/>
</w:rPr>
</w:pPr>
<w:r wsp:rsidRPr="00221D14">
<w:rPr>
<w:b-cs/>
<w:color w:val="0000A0"/>
</w:rPr>
<w:t>N/A</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>

<w:tr><w:tr>
.....Similar Rows...
</w:tbl>




XSLT:


<xsl:for-each select="ns1:tr">
<xsl:element name="Question">

<xsl:variable name="Questionrow">
<xsl:for-each select="ns1:tc/ns1:p/ns1:r">
<xsl:value-of select="ns1:t"/>
</xsl:for-each>
</xsl:variable>

<xsl:attribute name="label">
<xsl:value-of select="substring(normalize-space($Questionrow),1,1)"/>
</xsl:attribute>

<xsl:attribute name="displayorder">
<xsl:value-of select="position() - 2"/>
</xsl:attribute>

<xsl:attribute name="questiontype">
<xsl:text>DoDQuestion</xsl:text>
</xsl:attribute>

<xsl:element name="Text">
<xsl:variable name="length" select="string-length(substring-before(normalize-space($Questionrow),'?'))"/>
<xsl:value-of select="substring(normalize-space($Questionrow),3,($length))"/>
</xsl:element>

<xsl:element name="Subquestions">

<xsl:for-each select="following-sibling::*">
<![CDATA[Trying to do the same as above. But How to Exit this loop when next Question Comes.]]>
</xsl:for-each>
</xsl:element>
</xsl:element>

</xsl:for-each>






Required XML Format:

<Section label="2" title="OPERATIONS MANAGEMENT (Senior Ops Manager)" displayorder="1">
<Questions>
<Question label="a" displayorder="1" questiontype="DoDQuestion">
<Text>How would you assess your relationship with the FAA?</Text>
<AnswerChoices>
<AnswerChoice code="" label="" displayorder="0" type="text" />
</AnswerChoices>
</Question>
<Question label="b" displayorder="0" questiontype="DoDQuestion">
<Text>How does operations management emphasize safety as a top priority?</Text>
<AnswerChoices>
<AnswerChoice code="" label="" displayorder="0" type="text" />
</AnswerChoices>
<Subquestions>
<Subquestion label="1" level="1" displayorder="0" questiontype="DoDQuestion">
<Text>Is your safety philosophy published and accessible to line crewmembers?</Text>
<AnswerChoices>
<AnswerChoice code="Yes" label="Yes" displayorder="0" type="radio" />
<AnswerChoice code="No" label="No" displayorder="1" type="radio" />
<AnswerChoice code="NA" label="N/A" displayorder="2" type="radio" />
</AnswerChoices>
</Subquestion>
<Subquestion label="2" level="1" displayorder="1" questiontype="DoDQuestion">
<Text>Do you interact regularly with the company’s safety focal point?</Text>
<AnswerChoices>
<AnswerChoice code="Yes" label="Yes" displayorder="0" type="radio" />
<AnswerChoice code="No" label="No" displayorder="1" type="radio" />
<AnswerChoice code="NA" label="N/A" displayorder="2" type="radio" />
</AnswerChoices>
</Subquestion>
</Subquestions>
</Question>
<Question label="c" displayorder="2" questiontype="DoDQuestion">
<Text>Does your company operate into FAA or DOD designated special airfields?</Text>
<AnswerChoices>
<AnswerChoice code="Yes" label="Yes" displayorder="0" type="radio" />
<AnswerChoice code="No" label="No" displayorder="1" type="radio" />
<AnswerChoice code="NA" label="N/A" displayorder="2" type="radio" />
</AnswerChoices>
</Question>
<Question label="d" displayorder="3" questiontype="DoDQuestion">
<Text>Does your company operate any missions it considers higher risk than standard?</Text>
<AnswerChoices>
<AnswerChoice code="Yes" label="Yes" displayorder="0" type="radio" />
<AnswerChoice code="No" label="No" displayorder="1" type="radio" />
<AnswerChoice code="NA" label="N/A" displayorder="2" type="radio" />
</AnswerChoices>
<Subquestions>
<Subquestion label="•" level="1" displayorder="0" questiontype="DoDQuestion">
<Text>Have these been identified in operations manuals?</Text>
<AnswerChoices>
<AnswerChoice code="Yes" label="Yes" displayorder="0" type="radio" />
<AnswerChoice code="No" label="No" displayorder="1" type="radio" />
<AnswerChoice code="NA" label="N/A" displayorder="2" type="radio" />
</AnswerChoices>
</Subquestion>
<Subquestion label="•" level="1" displayorder="1" questiontype="DoDQuestion">
<Text>Is there oversight of scheduling for theses increased risk flights?</Text>
<AnswerChoices>
<AnswerChoice code="Yes" label="Yes" displayorder="0" type="radio" />
<AnswerChoice code="No" label="No" displayorder="1" type="radio" />
<AnswerChoice code="NA" label="N/A" displayorder="2" type="radio" />
</AnswerChoices>
</Subquestion>
</Subquestions>
</Question>
</Questions>
</Section>

Last edited by sudheer2250; May 21st, 2011 at 10:06 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exit from loop dishant XSLT 2 October 6th, 2008 03:34 AM
xslt:for-each - how can I exit/terminate a loop? john7321 XSLT 2 November 19th, 2007 08:28 PM
While loop urgent mikedeepak Classic ASP Databases 1 October 7th, 2005 03:04 AM
URGENT:For loop jyoti_khera XSLT 3 October 19th, 2004 08:04 AM
Problem with Loop?? Please URGENT peterallcdn Beginning PHP 1 November 27th, 2003 06:37 PM





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