Solved

Help performing a relative XSLT transformation

Posted on 2006-12-01
4
459 Views
Last Modified: 2012-05-05
Help performing a relative XSLT transformation

I have this page:
http://pdn.sieris.com/sieris/core8/example-page.php

in the XML I have:
<block>
      <text>
            random number -&gt; 760<br/>And 8 line breaks.<br/><br/><br/><br/><br/><br/><br/><br/>textbox ->
      </text>
      <textbox>
            <name>address</name>
      </textbox>
</block>



Then I have this as my XSLT:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" omit-xml-declaration="yes"/>
      <xsl:include href="widgets/block.xslt"/>
      <xsl:include href="widgets/textbox.xslt"/>
      <xsl:include href="widgets/text.xslt"/>
      <xsl:template name="widgets">
            <xsl:param name="thisNode"/>
            <xsl:for-each select="$thisNode/child::block">
                  <xsl:call-template name="block">
                        <xsl:with-param name="thisNode" select="."/>
                  </xsl:call-template>
            </xsl:for-each>
            <xsl:for-each select="$thisNode/child::textbox">
                  <xsl:call-template name="textbox">
                        <xsl:with-param name="thisNode" select="."/>
                  </xsl:call-template>
            </xsl:for-each>
            <xsl:for-each select="$thisNode/child::text">
                  <xsl:call-template name="text">
                        <xsl:with-param name="thisNode" select="."/>
                  </xsl:call-template>
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>


Problem is... this is my output:
<div><input name="address" type="text">random number -&gt; 98<br>And 9 line breaks. <br><br><br><br><br><br><br><br><br>textbox -&gt;</div>


Please help... I want everything to transform at it's current location. No matter how "deep" of a node it is. I want to be able to put these elements inside of each other with no limit.
Notice that the textbox is showing up before everything else. It is not showing up after the "text". The only part that is working correctly is that is is showing up within the "block", which is the div tag.
0
Comment
Question by:phobis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 18054241
Hi phobis,

having three for-each statements, you pull the nodes out of order
if you want to keep them in sync you will need something like this

          <xsl:for-each select="$thisNode/block | $thisNode/textbox | $thisNode/text">
                <xsl:choose>
                    <xsl:when test="name() = 'block'">
                          <xsl:call-template name="block">
                                <xsl:with-param name="thisNode" select="."/>
                           </xsl:call-template>
                    </xsl:when>
                    <xsl:when test="name() = 'textbox '">
                          <xsl:call-template name="'textbox">
                                <xsl:with-param name="thisNode" select="."/>
                           </xsl:call-template>
                    </xsl:when>
                    <xsl:when test="name() = block">
                          <xsl:call-template name="block">
                                <xsl:with-param name="thisNode" select="."/>
                           </xsl:call-template>
                    </xsl:when>
                </xsl:choose>
          </xsl:for-each>

This way, you don't change the order

Cheers!
0
 

Author Comment

by:phobis
ID: 18054341
Hi Gerton,

I tried your example:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" omit-xml-declaration="yes"/>
      <xsl:include href="widgets/block.xslt"/>
      <xsl:include href="widgets/textbox.xslt"/>
      <xsl:include href="widgets/text.xslt"/>
      <xsl:template name="widgets">
            <xsl:param name="thisNode"/>
            <xsl:for-each select="$thisNode/block | $thisNode/textbox | $thisNode/text">
                <xsl:choose>
                    <xsl:when test="name()='block'">
                          <xsl:call-template name="block">
                                <xsl:with-param name="thisNode" select="."/>
                           </xsl:call-template>
                    </xsl:when>
                    <xsl:when test="name()='textbox'">
                          <xsl:call-template name="textbox">
                                <xsl:with-param name="thisNode" select="."/>
                           </xsl:call-template>
                    </xsl:when>
                    <xsl:when test="name()='block'">
                          <xsl:call-template name="block">
                                <xsl:with-param name="thisNode" select="."/>
                           </xsl:call-template>
                    </xsl:when>
                </xsl:choose>
          </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>


Now my output looks like this:
<div><input name="address" type="text"></div>

It should look like this:
<div>random number -&gt; 98<br>And 9 line breaks. <br><br><br><br><br><br><br><br><br>textbox -&gt;<input name="address" type="text"></div>

it is currently at:
http://pdn.sieris.com/sieris/core8/example-page.php
(which seems to only work in Firefox right now, due to some javascript on the page that needs to be fixed)
0
 

Author Comment

by:phobis
ID: 18054377
LOL, sorry.

This was my fault... I did not see that
<xsl:when test="name()='block'">
                 <xsl:call-template name="block">
                         <xsl:with-param name="thisNode" select="."/>
                  </xsl:call-template>
</xsl:when>

Was listed twice  :)

I changed the second "block" block to be "text"

thank you!!! it all works now :)
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18054527
you are welcome,
sorry about my typo

cheers

Geert
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question