Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help performing a relative XSLT transformation

Posted on 2006-12-01
4
Medium Priority
?
462 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

604 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