This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: problem with transforming-copying same level elements --2nd Posting--


Saxon 7.0 is the only implementation of XSLT 2.0 currently available, and
it's incomplete (as is XSLT 2.0 itself). If you're not confident enough to
work out from the instructions on the Saxon web set (http://saxon.sf.net/)
how to use it, then you should probably avoid it: it's bleeding-edge stuff.

Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com

> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of
> Uslu, Cihan Y
> (MED)
> Sent: 28 March 2002 19:07
> To: 'xsl-list@lists.mulberrytech.com'
> Subject: RE: [xsl] problem with transforming-copying same
> level elements
> --2nd Posting--
>
>
> Michael,
> Thank you for your reply. I appreciate you taking time and giving your
> thoughts on this subject. Now, If I want to use XSLT2.0 ,
> what should I
> include in my environment, is it possible to the same kind of
> transformation with JSP, by calling the XSL from JSP page? Is
> there any
> examples of XSLT 2.0 being used this way, and If yes; Could you please
> direct me to those examples. I'm using xselerator to code and test my
> XSL scripts, is it possible to integrate XSLT 2.0 and the transformer
> (that would be Saxon 7.0?) into this tool.
> Is there any other things I should be careful when I use XSLT 2.0?
>
> Thanks.
>
> Ci
> -----Original Message-----
> From: Michael Kay [mailto:michael.h.kay@ntlworld.com]
> Sent: Thursday, March 28, 2002 11:00 AM
> To: xsl-list@lists.mulberrytech.com
> Subject: RE: [xsl] problem with transforming-copying same
> level elements
> --2nd Posting--
>
>
> Sometimes this kind of grouping problem is much easier to tackle in a
> different language. Consider writing a SAX filter which adds start and
> end
> tags to create the hierarchic structure which Framemaker has so
> miserably
> failed to provide (sometimes one gets the impression that
> these exported
> XML
> formats were designed to get a tick in the "supports XML" box, rather
> than
> to provide any useful functionality).
>
> Or you should be able to do this quite easily with <xsl:for-each-group
> group-starting-at> in XSLT 2.0.
>
> Michael Kay
> Software AG
> home: Michael.H.Kay@ntlworld.com
> work: Michael.Kay@softwareag.com
>
> > -----Original Message-----
> > From: owner-xsl-list@lists.mulberrytech.com
> > [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of
> > Uslu, Cihan Y
> > (MED)
> > Sent: 28 March 2002 14:45
> > To: 'xsl-list@lists.mulberrytech.com'
> > Subject: RE: [xsl] problem with transforming-copying same
> > level elements
> > --2nd Posting--
> >
> >
> > Michael,
> > Thank you for you reply, I receive my input from FrameMaker to XML
> > conversion and I have no control over the input XML.
> Unfortunetly the
> > structure of XML is different than what you guessed. Tag
> > <Body-Text> is
> > not parent to neither <answer> nor
> > <distractorList><distractor/></distractorList>, and there
> may be many
> > <question>, <answer/>, <distractorList><distractor/><distractorList>
> > combination after the tag <Body-Text> with the string value of... .
> > Having all the tags as siblings to each other makes it
> really hard for
> > me to group them under separate modules.
> > They're all at the same level. I'm using xalan for
> transformation, and
> > this XSL is being called by JSP page. After I transform the XML into
> > targeted XML structure then I convert it to EDI file and
> > upload it into
> > a remote server for EDI processing.
> > I've appended my XSL script after the XML structure text, so you can
> > look at it and may be tell me what I need to do to make it work.
> >
> > This is the input XML structure:
> > ----------------------------------------------
> > <XML>
> > <stuff/>
> > <Body-Text/><!-- This is my start point of Module One, and the
> > question,answer, and distractors of Module One-->
> > <question/>  <!--first question -->
> > <answer/>
> > <distarctorList>
> > 	<distractor/>
> > </distractorList>
> > <question/> <!--second question -->
> > <distractorList>
> > 	<distractor/>
> > 	<distractor/>
> > </distractorList>
> > <answer/>
> > <distractorList>
> > 	<distractor/>
> > </distractorList>
> > ..... <!-- Other question, answer,distractors -->
> > <Body-Text> <!-- This is my start point for Module Two
> > <question/>  <!--first question-->
> > <answer/>
> > <distarctorList>
> > 	<distractor/>
> > </distractorList>
> > <question/> <!--second question -->
> > <distractorList>
> > 	<distractor/>
> > 	<distractor/>
> > </distractorList>
> > <answer/>
> > <distractorList>
> > 	<distractor/>
> > </distractorList>
> > <stuff/>
> > </XML>
> >
> >
> > This is the XSL script I'm working on it, it works up o assessment
> > level, where I am able to copy the question and its content into
> > assessment. For answer and distractors, I've tried every
> other way but
> > no luck, I can not get them under assessment and group them.
> >
> > -------------------------------------
> > <xsl:template match="XML">
> > <xsl:element name="course">
> >  	<xsl:attribute name="courseNum">
> > 		<xsl:value-of
> > select="normalize-space(.//courseNum/text())"/> <!-- There
> is only one
> > courseNum element, that's why this selection is gloabl-->
> > 	</xsl:attribute>
> >  	<xsl:attribute name="owner">
> >  		<xsl:value-of select="''"/>
> >  	</xsl:attribute>
> >  	<xsl:attribute name="ownerEmail">
> >  		<xsl:value-of select="''"/>
> >  	</xsl:attribute>
> >     <xsl:for-each select="Body-Text[contains(.,'To be
> eligible for CE
> > credit')]">
> >    		<xsl:if test="count(preceding-sibling::Body-Text[text()
> > = current()/text()]) =0">
> >                <xsl:element name="module">
> >              		<xsl:attribute
> > name="test-type">S</xsl:attribute>
> > 					<xsl:attribute
> > name="show-test-feedback">N</xsl:attribute>
> > 					<xsl:attribute
> > name="allow-test-review">Y</xsl:attribute>
> > 					<xsl:attribute
> > name="required">Y</xsl:attribute>
> > 					<xsl:attribute
> > name="content">Click CONTINUE to begin the
> assessment.</xsl:attribute>
> > 					<xsl:attribute
> > name="passing-score">0</xsl:attribute>
> > 					<xsl:attribute
> > name="test-out-score">0</xsl:attribute>
> > 					<xsl:element name="title">
> > 						<xsl:element
> > name="para">Pre-Assessment</xsl:element>
> >     					</xsl:element>
> > 	       	 		<xsl:element name="intro">
> > 	        			<xsl:element name="para">This is
> > the pre-program assessment test for
> > 	        				<xsl:value-of
> > select="$title"/>. Please click CONTINUE to proceed.
> > 	        			</xsl:element>
> > 	       		 	</xsl:element>
> >          		   <xsl:for-each
> > select="following-sibling::*/self::question">
> >          		   	<xsl:if
> > test="count(preceding-sibling::Body-Text[text() =
> > preceding-sibling::*/text()]) =0">
> >          		   		<xsl:element name="assessment">
> >          		   			<xsl:element
> > name="question">
> >          		   				<xsl:element
> > name="stem">
> >
> > <xsl:element name="para">
> >
> > <xsl:copy-of select="* | text()"/>
> >
> > </xsl:element>
> >          		   				</xsl:element>
> >
> >          		   			</xsl:element>
> >          		   		</xsl:element>
> >          		   	</xsl:if>
> >          		   </xsl:for-each>
> >                      <!-- I need to do something here for
> the answers
> > and distractors-->
> >   		</xsl:element>
> >        </xsl:if>
> >       <xsl:if test="count(preceding-sibling::Body-Text[text() =
> > current()/text()]) =1">
> > 			<xsl:element name="module">
> >              	<xsl:attribute
> name="test-type">P</xsl:attribute>
> > 				<xsl:attribute
> > name="required">Y</xsl:attribute>
> > 				<xsl:attribute name="content">Click
> > CONTINUE to begin the assessment.</xsl:attribute>
> >     			<xsl:attribute
> > name="test-out-score">0</xsl:attribute>
> > 				<xsl:element name="title">
> > 					<xsl:element
> > name="para">Post-Assessment</xsl:element>
> >     			</xsl:element>
> > 	       	 	<xsl:element name="intro">
> > 	        		<xsl:element name="para">This is the
> > post-program assessment test for
> > 	        			<xsl:value-of select="$title"/>.
> > Please do not complete the assessment until after you have
> viewed the
> > TiP broadcast. When you are ready to take the assessment,
> > click CONTINUE
> > to proceed.
> > 	        		</xsl:element>
> > 	       		 </xsl:element>
> >                  <xsl:for-each
> > select="following-sibling::*/self::question">
> >     				<xsl:if
> > test="count(preceding-sibling::Body-Text[text() =
> > preceding-sibling::*/text()]) =1">
> >     				<xsl:element
> > name="assessment"></xsl:element>
> >     				</xsl:if>
> >     			</xsl:for-each>
> >   			</xsl:element>
> >      	</xsl:if>
> > 	</xsl:for-each>
> > </xsl:element>
> > </xsl:template>
> >
> >
> > -----Original Message-----
> > From: Michael Kay [mailto:michael.h.kay@ntlworld.com]
> > Sent: Thursday, March 28, 2002 3:42 AM
> > To: xsl-list@lists.mulberrytech.com
> > Subject: RE: [xsl] problem with transforming-copying same
> > level elements
> > --2nd Posting--
> >
> >
> > > For each <Body-Text> tag with string value of "To be
> eligible for CE
> > > credit", I need to create a <module> element and for each
> > > <question> tag
> > > create a child element named <assessment> and copy the
> xml/question,
> > > xml/answer and distractorList/distractor and their contents
> > > as childs of <assessment> tag.
> > >
> > Minor point, you shouldn't be using "<XML>" as an element name. It's
> > reserved.
> >
> > In your example each Body-Text contains exactly one question and one
> > answer?
> > If that's always true, then it's easy. I'm guessing that the real
> > structure
> > is:
> >
> > <body-text>
> >   <question/>
> >   <xxx/>
> >   <answer/>
> >   <xxx/>
> >   <question/>
> >   <xxx/>
> >   <answer/>
> >   <xxx/>
> >   <question/>
> >   <xxx/>
> >   <answer/>
> >   <xxx/>
> > </body-text>
> >
> > This is a particularly knotty kind of grouping
> > transformation. It's easy
> > in
> > XSLT 2.0 (you can try this with Saxon 7.0):
> >
> > <xsl:for-each-group group-starting-at="question">
> > <assessment>
> >   <question><xsl:value-of
> > select="current-group()/question"/></question>
> >   <answer><xsl:value-of select="current-group()/question"/></answer>
> > </assessment>
> >
> > It's harder with XSLT 1.0, but by no means impossible. I would do it
> > along
> > the following lines:
> >
> > <xsl:template match="Body-Text[.='.....']">
> > <module>
> > <xsl:apply-templates select="question[1]"/>
> > </module>
> > </xsl:template>
> >
> > <xsl:template match="question">
> > <assessment>
> >   <question><xsl:value-of select="."/></question>
> >   <answer><xsl:value-of
> > select="following-sibling::answer[1]"/></answer>
> > <assessment
> > <xsl:apply-templates select="following-sibling::question[1]"/>
> > </xsl:template>
> >
> > I'm afraid I've abstracted from the detail of your actual input and
> > output
> > here, you'll have to sort out the detail yourself. The <distraction>
> > elements might make the detail a fair bit more complicated
> than this;
> > the
> > trick is to select those <distraction> elements whose
> > preceding-sibling::question[1] is the current question,
> which you can
> > test
> > using generate-id().
> >
> > Michael Kay
> > Software AG
> > home: Michael.H.Kay@ntlworld.com
> > work: Michael.Kay@softwareag.com
> >
> > >
> > > TARGETED XML
> > > --------------------------
> > > <course>
> > > <module>
> > > 	<assessment>
> > > 		<question>
> > > 		   <stem>
> > > 			<para>some text here</para>
> > > 		</stem>
> > > 		<answer> This is answer</answer>
> > > 		<distractor> This is distractor 1</distractor>
> > > 		<distractor> This is distractor 2</distractor>
> > > 		</question>
> > > 	</assessment>
> > > 	.....
> > > </module>
> > > <module>
> > > 	<assessment>
> > > 		<question>
> > > 		   <stem>
> > > 			<para>some more text here</para>
> > > 		</stem>
> > > 		<distractor> This is another distractor 1</distractor>
> > > 		<answer>This is another answer</answer>
> > > 		<distractor> This is another distractor 2</distractor>
> > > 		<distractor> This is another distractor 3</distractor>
> > > 		</question>
> > > 	</assessment>
> > > 	.....
> > > </module>
> > > </course>
> > >
> > >
> > >
> > >
> > > INPUT XML
> > > -------------
> > > <XML>
> > > <Body-Text>To be eligible for CE credit</Body-Text>
> > > <question>some text here</question>
> > > <distractorList>
> > > 	<distractor>This is distractor 1</distractor>
> > > </distractorList>
> > > <answer>This is answer</answer>
> > > <distractorList>
> > > 	<distractor>This is distractor 2</distractor>
> > > 	<distractor>This is distractor 3</distractor>
> > > </distractorList>
> > > ......
> > > <Body-Text>To be eligible for CE credit</Body-Text>
> > > <question>some more text here</question>
> > > <distractorList>
> > > 	<distractor> This is another Distractor 1</distractor>
> > > </distractorList>
> > > <answer>This is another answer</answer>
> > > <distractorList>
> > > 	<distractor>This is another Distractor 2</distractor>
> > > 	<distractor>This is another Distractor 3</distractor>
> > > </distractorList>
> > > </XML>
> > >
> > >
> > >  XSL-List info and archive:
> http://www.mulberrytech.com/xsl/xsl-list
> >
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]