[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl problem (xalan:nodeset)

Subject: Re: xsl problem (xalan:nodeset)
From: "poppe chris" <pc_poppe@xxxxxxxxxxx>
Date: Mon, 12 Apr 2004 10:59:12 +0200
xalan nodeset
Hello,

first of all thanks for this reply cause it has helped me in solving my problems. I had a further question regarding the xalan:nodeset
you used something like


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">


I dont really understand what this does (being the noob that i am) especially the exclude-result-prefixes.
I use a java xslt processor (org.apache.xalan.xslt.Process), so when i use the xalan namespace, can i process this stylesheet with other processors too?


regards,
Chris Poppe


From: Mukul Gandhi <mukulgandhi2003@xxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  xsl problem
Date: Tue, 30 Mar 2004 19:03:19 +0100 (BST)

Hi Chris,
  Please find below the solution to the problem
described by you -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>

<xsl:template match="/root">
   <xsl:apply-templates select="GOP/content"/>
</xsl:template>

<xsl:template match="GOP/content">
  <xsl:variable name="rtf">
     <xsl:for-each select="*">
	<xsl:if test="name() = 'A' ">
	  <A>						     <xsl:call-template name="process-a1">
		<xsl:with-param name="str" select="."/>
             </xsl:call-template>
	  </A>
	</xsl:if>
     </xsl:for-each>
  </xsl:variable>

  <header>
    <size>
	<xsl:value-of select="sum(xalan:nodeset($rtf)/A)"/>
    </size>
  </header>
  <xsl:for-each select="*">
    <xsl:if test="name() = 'A' ">
      <A>
	<xsl:call-template name="process-a2">
	   <xsl:with-param name="str" select="."/>
	</xsl:call-template>
      </A>
    </xsl:if>
    <xsl:if test="name() = 'B' ">
       <xsl:copy-of select="." />
    </xsl:if>
  </xsl:for-each>
</xsl:template>

<xsl:template name="process-a1">
  <xsl:param name="str"/>
  <xsl:variable name="str1"
select="substring-after($str, ' ')"/>
  <xsl:if test="$str1 &lt; 10">
    <xsl:value-of select="$str1 + 3"/>
  </xsl:if>
  <xsl:if test="not($str1 &lt; 10)">
    <xsl:value-of select="$str1"/>
  </xsl:if>
</xsl:template>

<xsl:template name="process-a2">
   <xsl:param name="str"/>
   <xsl:variable name="str1"
select="substring-before($str, ' ')"/>
   <xsl:variable name="str2"
select="substring-after($str, ' ')"/>
   <xsl:value-of select="$str1" /><xsl:text>
</xsl:text>
   <xsl:if test="$str2 &lt; 10">
      <xsl:value-of select="$str2 + 3"/>
   </xsl:if>
   <xsl:if test="not($str2 &lt; 10)">
      <xsl:value-of select="$str2"/>
   </xsl:if>
</xsl:template>

</xsl:stylesheet>

I have used the nodeset extension function, to do two
pass traversal of the XML by the stylesheet.

I added the <root> tag to make the XML well-formed.

Regards,
Mukul


--- poppe chris <pc_poppe@xxxxxxxxxxx> wrote: > Hello, Im facing the following problem, > > I have a xml file like this, in wich an A element > contains an offset (20, > 30, 40) and a length (5, 10, 5) and the size element > in the header is the > sum of the lengths. > > <header> > <size>20</size> > </header> > <GOP> > <content> > <A>20 5</A> > <B/> > <A>30 10</A> > <A>40 5</A> > <B/> > </content> > </GOP> > > What i want to do is match any A element and alter > the length for example > everywhere + 3 except for lenghts greater then or > equal to 10. But the > problem is that I then have to change the size. > So the outputxml file should be: > > <header> > <size>26</size> > </header> > <GOP> > <content> > <A>20 8</A> > <B/> > <A>30 10</A> > <A>40 8</A> > <B/> > </content> > </GOP> > > I dont have a problem changing the A elements but i > do have a problem in > changing the size to the right number. Currently im > using 2 xsl files to > solve this, one to change the A elements and put the > changed length in an > helper element, this produces the following xml file > > <header> > <size>20</size> > </header> > <GOP> > <content> > <A>20 8</A> > <help>8</help> > <B/> > <A>30 10</A> > <help>10</help> > <A>40 8</A> > <help>8</help> > <B/> > </content> > </GOP> > > And then i use another xsl transformation to change > the size. > > I would love to see all this happen in one xsl > transformation, > > anyone got any idea's? > greetings, > Chris > > _________________________________________________________________ > Ben jij klaar voor De Vuilbek? > http://devuilbek.msn.be/start.php Nu op JIM > en MSN >

________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more.
Go to: http://in.insurance.yahoo.com/licspecial/index.html



_________________________________________________________________ Online gamen ? http://www.msn.be/games/online/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.