Solved

Help performing a relative XSLT transformation

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Conditional Formatting 4 35
XSLT: how to increment number value if attribute present 4 35
XSL FO - text wrapping and empty spaces 1 26
AL3 Files 4 13
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.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now