Solved

Help performing a relative XSLT transformation

Posted on 2006-12-01
4
454 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

810 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