 |
| 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
|
|
|
|

June 6th, 2012, 03:10 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Placement of <div>
Hi Experts,
I am very new to XSLT so request you to please help me with this easy question.
I need to transform a HTML into XSLT i have few questions on it.
I have the following divs
<div class="modulo">
<div class="item"></div>
<div class="item"></div>
</div>
<div class="modulo">
<div class="item"></div>
<div class="item"></div>
</div>
<div class="modulo">
<div class="item"></div>
<div class="item"></div>
</div>
<div class="modulo">
<div class="item"></div>
<div class="item"></div>
</div>
Now by writing the XSLT i need to get the "modulo" div after 2 item divs have been added.
I have written a plain XSLT like
<xsl:for-each select="/Properties/Data/Result/QueryOutput/DigitalInterview">
<div class="modulo">
<div class="item">
</div><!--/item-->
</div><!--/modulo-->
</xsl:for-each>
Request you to please help me in getting the ouput in the above html format.
|
|

June 6th, 2012, 04:40 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I'm sorry, I don't understand the question. It's not clear to me what the input of your transformation is, it's not clear what output is required, and I don't understand the sentence "i need to get the "modulo" div after 2 item divs have been added".
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

June 6th, 2012, 06:02 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your reply. I have this HTML code
<div class="modulo">
<div class="item"></div>
<div class="item"></div>
</div>
<div class="modulo">
<div class="item"></div>
<div class="item"></div>
</div>
<div class="modulo">
<div class="item"></div>
<div class="item"></div>
</div>
<div class="modulo">
<div class="item"></div>
<div class="item"></div>
</div>
Now while writing the XSLT i need to get the loop for <div class="modulo">
and <div class="item"> in such a manner that after every 2 <div class="item"> there is new <div class="modulo">
. By writing the current XSLT :-
<xsl:for-each select="/Properties/Data/Result/QueryOutput/DigitalInterview">
<div class="modulo">
<div class="item">
</div><!--/item-->
</div><!--/modulo-->
</xsl:for-each>
I get the output as :-
<div class="modulo">
<div class="item"></div>
</div>
<div class="modulo">
<div class="item"></div>
</div>
<div class="modulo">
<div class="item"></div>
</div>
whereas I need the output as mentioned above.
|
|

June 6th, 2012, 06:36 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
You're generating one item for every modulo, if you want to generate two can't you just change the code to
Code:
<xsl:for-each select="/Properties/Data/Result/QueryOutput/DigitalInterview">
<div class="modulo">
<div class="item">
</div><!--/item-->
<div class="item">
</div><!--/item-->
</div><!--/modulo-->
</xsl:for-each>
That seems so elementary that I might have misunderstood, but you really aren't making yourself very clear. I asked you to show the input and output documents, and you haven't done so.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

June 6th, 2012, 06:55 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Okies attach are the input code which is an xml
Code:
<DigitalInterview><absolutepath>/default/main/cadena_ser/WORKAREA/shared/templatedata/cadena_ser/entrevistas/data/2012/03/08/ManmohanSingh</absolutepath><interview_name>Interview with Dr. Manmohan Singh</interview_name><introduction><p>Interview with Dr. Manmohan Singh! tonight! Dont miss it!</p></introduction><start_date_readable_format>08/03/2012</start_date_readable_format><start_time_readable_format>8:52a.m.</start_time_readable_format><start_time>2012-03-08 08:52:00.0</start_time><end_date_readable_format>08/03/2012</end_date_readable_format><end_time_readable_format>8:52a.m.</end_time_readable_format><end_time>2012-03-08 08:52:00.0</end_time><status>cerrada</status><username/><password/><dcrvpath>templatedata/cadena_ser/entrevistas/data/2012/03/08/ManmohanSingh</dcrvpath><short_description><p>Prime minister of India</p></short_description><long_description><p>Interview with Dr. Manmohan Singh! tonight!</p></long_description><small_image>/templatedata/cadena_ser/foto/data/2012/03/16/20120316_foto_1</small_image><main_image>/templatedata/cadena_ser/foto/data/2012/03/16/20120316_foto_1</main_image><programa>78</programa><emisora>176</emisora><portal>1</portal></DigitalInterview>
<DigitalInterview><absolutepath>/default/main/cadena_ser/WORKAREA/shared/templatedata/cadena_ser/entrevistas/data/2012/03/08/20120308_entrevistas_1</absolutepath><interview_name>This is my test person 345!</interview_name><introduction><p>Dont miss this interview!! 60 Minute exclusive!</p></introduction><start_date_readable_format>08/03/2012</start_date_readable_format><start_time_readable_format>8:52a.m.</start_time_readable_format><start_time>2012-03-08 08:52:00.0</start_time><end_date_readable_format>08/03/2012</end_date_readable_format><end_time_readable_format>8:52a.m.</end_time_readable_format><end_time>2012-03-08 08:52:00.0</end_time><status>cerrada</status><username/><password/><dcrvpath>templatedata/cadena_ser/entrevistas/data/2012/03/08/20120308_entrevistas_1</dcrvpath><short_description>Director General of policia</short_description><long_description><p>Dont miss this interview!! 60 Minute exclusive!</p></long_description><small_image>/templatedata/cadena_ser/foto/data/2012/03/16/20120316_foto_1</small_image><main_image>jh</main_image><programa>78</programa><emisora>176</emisora><portal>1</portal></DigitalInterview>
<DigitalInterview><absolutepath>/default/main/cadena_ser/WORKAREA/shared/templatedata/cadena_ser/entrevistas/data/2012/04/25/20120425_entrevistas_2</absolutepath><interview_name>Barack Obama</interview_name><introduction><p>Una descripción de la entrevista aquí.</p></introduction><start_date_readable_format>25/04/2012</start_date_readable_format><start_time_readable_format>5:11p.m.</start_time_readable_format><start_time>2012-04-25 17:11:00.0</start_time><end_date_readable_format>25/04/2012</end_date_readable_format><end_time_readable_format>5:11p.m.</end_time_readable_format><end_time>2012-04-25 17:11:00.0</end_time><status>cerrada</status><username/><password/><dcrvpath>templatedata/cadena_ser/entrevistas/data/2012/04/25/20120425_entrevistas_2</dcrvpath><short_description><p>Cargo Corto</p></short_description><long_description><p>Carlo largo. un poco más largo</p></long_description><small_image>/templatedata/cadena_ser/foto/data/2012/04/25/20120425_foto_1</small_image><main_image>/templatedata/cadena_ser/foto/data/2012/04/25/20120425_foto_1</main_image><programa>250</programa><emisora>1</emisora><portal>1</portal></DigitalInterview>
output required is html code which is also attached.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<body>
<!-- START 5.39 -->
<div class="realizados_5_39_675">
<div class="mod-inter-675">
<!-- START Component Title-->
<h2>ENTREVISTAS REALIZADAS</h2>
<!-- END Component Title-->
<div class="modulo">
<div class="item">
<div class="image-realizados">
<!-- START Image path-->
<a href="#" title=""><img src="../img/maquetacion/noticia_250x140.jpg" /> </a>
<!-- END Image path-->
</div>
<div class="info-realizados">
<!-- START Topic-->
<span class="topic">ciencia</span>
<!-- END Topic -->
<!-- START Interviewee -->
<a class="interviewe">Jesús Gallego</a>
<!-- END Interviewee -->
<!-- START Interviewee Job -->
<span class="job">Directora de Informativos.</span>
<!-- END Interviewee Job-->
<!-- START Description-->
<p class="description">Fusce commodo do eros in nunc, commo eros in usce commodo do eros in nunc, commo eros in ommo eros in usce.</p>
<!-- END Description-->
<!-- START DI Date -->
<span class="hora">12.12.2012</span>
<!-- END DI Date -->
</div><!--/info-realizados-->
</div><!--/item-->
<div class="item">
<div class="image-realizados">
<!-- START Image path-->
<a href="#" title=""><img src="../img/maquetacion/noticia_250x140.jpg" /> </a>
<!-- END Image path-->
</div>
<div class="info-realizados">
<!-- START Topic-->
<span class="topic">ciencia</span>
<!-- END Topic -->
<!-- START Interviewee -->
<a class="interviewe">Jesús Gallego</a>
<!-- END Interviewee -->
<!-- START Interviewee Job -->
<span class="job">Directora de Informativos.</span>
<!-- END Interviewee Job-->
<!-- START Description-->
<p class="description">Fusce commodo.</p>
<!-- END Description-->
<!-- START DI Date -->
<span class="hora">12.12.2012</span>
<!-- END DI Date -->
</div><!--/info-realizados-->
</div><!--/item-->
</div><!--/modulo-->
<div class="modulo">
<div class="item">
<div class="image-realizados">
<!-- START Image path-->
<a href="#" title=""><img src="../img/maquetacion/noticia_250x140.jpg" /> </a>
<!-- END Image path-->
</div>
<div class="info-realizados">
<!-- START Topic-->
<span class="topic">ciencia</span>
<!-- END Topic -->
<!-- START Interviewee -->
<a class="interviewe">Jesús Gallego</a>
<!-- END Interviewee -->
<!-- START Interviewee Job -->
<span class="job">Directora de Informativos.</span>
<!-- END Interviewee Job-->
<!-- START Description-->
<p class="description">Fusce commodo do eros in nunc, commo eros in usce commodo do eros in nunc, commo eros in ommo eros in usce.</p>
<!-- END Description-->
<!-- START DI Date -->
<span class="hora">12.12.2012</span>
<!-- END DI Date -->
</div><!--/info-realizados-->
</div><!--/item-->
<div class="item">
<div class="image-realizados">
<!-- START Image path-->
<a href="#" title=""><img src="../img/maquetacion/noticia_250x140.jpg" /> </a>
<!-- END Image path-->
</div>
<div class="info-realizados">
<!-- START Topic-->
<span class="topic">ciencia</span>
<!-- END Topic -->
<!-- START Interviewee -->
<a class="interviewe">Jesús Gallego</a>
<!-- END Interviewee -->
<!-- START Interviewee Job -->
<span class="job">Directora de Informativos.</span>
<!-- END Interviewee Job-->
<!-- START Description-->
<p class="description">Fusce commodo.</p>
<!-- END Description-->
<!-- START DI Date -->
<span class="hora">12.12.2012</span>
<!-- END DI Date -->
</div><!--/info-realizados-->
</div><!--/item-->
</div><!--/modulo-->
<div class="modulo">
<div class="item">
<div class="image-realizados">
<!-- START Image path-->
<a href="#" title=""><img src="../img/maquetacion/noticia_250x140.jpg" /> </a>
<!-- END Image path-->
</div>
<div class="info-realizados">
<!-- START Topic-->
<span class="topic">ciencia</span>
<!-- END Topic -->
<!-- START Interviewee -->
<a class="interviewe">Jesús Gallego</a>
<!-- END Interviewee -->
<!-- START Interviewee Job -->
<span class="job">Directora de Informativos.</span>
<!-- END Interviewee Job-->
<!-- START Description-->
<p class="description">Fusce commodo do eros in nunc, commo eros in usce commodo do eros in nunc, commo eros in ommo eros in usce.</p>
<!-- END Description-->
<!-- START DI Date -->
<span class="hora">12.12.2012</span>
<!-- END DI Date -->
</div><!--/info-realizados-->
</div><!--/item-->
<div class="item">
<div class="image-realizados">
<!-- START Image path-->
<a href="#" title=""><img src="../img/maquetacion/noticia_250x140.jpg" /> </a>
<!-- END Image path-->
</div>
<div class="info-realizados">
<!-- START Topic-->
<span class="topic">ciencia</span>
<!-- END Topic -->
<!-- START Interviewee -->
<a class="interviewe">Jesús Gallego</a>
<!-- END Interviewee -->
<!-- START Interviewee Job -->
<span class="job">Directora de Informativos.</span>
<!-- END Interviewee Job-->
<!-- START Description-->
<p class="description">Fusce commodo.</p>
<!-- END Description-->
<!-- START DI Date -->
<span class="hora">12.12.2012</span>
<!-- END DI Date -->
</div><!--/info-realizados-->
</div><!--/item-->
</div><!--/modulo-->
<div class="modulo">
<div class="item">
<div class="image-realizados">
<!-- START Image path-->
<a href="#" title=""><img src="../img/maquetacion/noticia_250x140.jpg" /> </a>
<!-- END Image path-->
</div>
<div class="info-realizados">
<!-- START Topic-->
<span class="topic">ciencia</span>
<!-- END Topic -->
<!-- START Interviewee -->
<a class="interviewe">Jesús Gallego</a>
<!-- END Interviewee -->
<!-- START Interviewee Job -->
<span class="job">Directora de Informativos.</span>
<!-- END Interviewee Job-->
<!-- START Description-->
<p class="description">Fusce commodo do eros in nunc, commo eros in usce commodo do eros in nunc, commo eros in ommo eros in usce.</p>
<!-- END Description-->
<!-- START DI Date -->
<span class="hora">12.12.2012</span>
<!-- END DI Date -->
</div><!--/info-realizados-->
</div><!--/item-->
<div class="item">
<div class="image-realizados">
<!-- START Image path-->
<a href="#" title=""><img src="../img/maquetacion/noticia_250x140.jpg" /> </a>
<!-- END Image path-->
</div>
<div class="info-realizados">
<!-- START Topic-->
<span class="topic">ciencia</span>
<!-- END Topic -->
<!-- START Interviewee -->
<a class="interviewe">Jesús Gallego</a>
<!-- END Interviewee -->
<!-- START Interviewee Job -->
<span class="job">Directora de Informativos.</span>
<!-- END Interviewee Job-->
<!-- START Description-->
<p class="description">Fusce commodo.</p>
<!-- END Description-->
<!-- START DI Date -->
<span class="hora">12.12.2012</span>
<!-- END DI Date -->
</div><!--/info-realizados-->
</div><!--/item-->
</div><!--/modulo-->
</div><!--/mod-inter-675-->
<div class="mod-pie-675">
<a href="#" title="ver todo" class="goto">ver todo</a>
</div> <!--/mod-pie-675-->
</div><!--/realizados_5_39_675-->
<!-- END 5.39 -->
</body>
</html>
I use xslt code to transform the input xml to the output html.
Code:
<xsl:template match="/">
<!-- get Image Path -->
<xsl:variable name="imagePath">
<xsl:variable name="tempPath" select="fileUtils:getImagePath()" />
<xsl:if test="$tempPath=''">
$URL_PREFIX
</xsl:if>
<xsl:if test="not($tempPath='')">
<xsl:value-of disable-output-escaping="yes" select="$tempPath" />
</xsl:if>
</xsl:variable>
<div class="realizados_5_39_675">
<div class="mod-inter-675">
<h2>
<xsl:value-of disable-output-escaping="yes" select="/Properties/Data/Datum[@ID='title']" />
</h2>
<xsl:for-each select="/Properties/Data/Result/QueryOutput/DigitalInterview">
<div class="modulo">
<div class="item">
<div class="image-realizados">
<xsl:variable name="filePath" select="fileUtils:getDocumentPath()" />
<xsl:variable name="photoDCR" select="document( concat($filePath, '/', small_image) )" />
<img src="$URL_PREFIX{imageLoader:imagePathFromPhotoDCR( $photoDCR, '4_3_300' )}"/>
</div>
<xsl:variable name="friendlyUrl">
<xsl:value-of select="dcrUtils:getfriendlyURLByPath(dcrvpath)"/>
</xsl:variable>
<div class="info-realizados">
<span class="topic"></span>
<a class="interviewe"><xsl:value-of disable-output-escaping="yes" select="interview_name" /></a>
<span class="job"><xsl:value-of disable-output-escaping="yes" select="short_description" /></span>
<p class="description"><xsl:value-of disable-output-escaping="yes" select="introduction" /></p>
<span class="hora"><xsl:value-of disable-output-escaping="yes" select="start_date_readable_format" /></span>
</div>
</div>
</div>
</xsl:for-each>
</div>
<div class="mod-pie-675">
<a class="goto" title="ver todo">
<xsl:attribute name="href"><xsl:value-of disable-output-escaping="yes" select="/Properties/Data/Datum[@Name='VerMas']" /></xsl:attribute>
ver todo
</a>
</div>
</div>
</xsl:template>
|
|

June 6th, 2012, 07:27 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Your XSLT contains a lot of calls to extension functions which means I can't actually run it to see what it does; also you've excluded part of the source document which I would need to reconstruct to make your code executable. You may be better off trying to create a synthetic example, that is fully runnable, and that shows the essence of what you are trying to achieve and where your problem lies.
Get rid of all this disable-output-escaping stuff, by the way. It's a reliable indicator that the author doesn't understand XSLT when you see this liberally sprinkled over the code.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

June 6th, 2012, 07:46 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Michael,
Its really something basic which i am missing out in the xslt code.
I need the html output as
Code:
<html>
<body>
<div class="modulo">
<h2>heading1</h2>
<div classs="item">
<p>item1</p>
</div>
<div classs="item">
<p>item2</p>
</div>
</div>
<div class="modulo">
<h2>heading2</h2>
<div classs="item">
<p>item3</p>
</div>
<div classs="item">
<p>item4</p>
</div>
</div>
</body>
</html>
but using the XSLT to transform the xml i get the HTML as
Code:
<html>
<body>
<div class="modulo">
<h2>heading1</h2>
<div classs="item">
<p>item1</p>
</div>
</div>
<div class="modulo">
<h2>heading1</h2>
<div classs="item">
<p>item2</p>
</div>
</div>
<div class="modulo">
<h2>heading2</h2>
<div classs="item">
<p>item3</p>
</div>
</div>
<div class="modulo">
<h2>heading2</h2>
<div classs="item">
<p>item3</p>
</div>
</div>
<div class="modulo">
<h2>heading2</h2>
<div classs="item">
<p>item4</p>
</div>
</div>
</body>
</html>
Only thing i need to know in XSLT how do I get the output in the correct format.I thnik i need to use position() function not sure how to implement it.
|
|
 |