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

Re: Simple Question

Subject: Re: Simple Question
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 30 Jan 2007 22:19:52 +0100
Re:  Simple Question
Punnoose, Roshan wrote:
I know that this is a really simple question but I just can't seem to
figure it out. I want to print out xml if a certain condition is true,
so I thought the bottom would work, but of course it isn't valid xml.
Any ideas?

<xsl:if test="$a != $times">
<xqx:orOp>
<xqx:firstOperand>
</xsl:if>

I am under the impression that you omit a part. Is this what you are trying?


<xsl:if test="somecondition">
   <sometag>  <!-- open the tag -->
</xsl:if>

...

<xsl:if test="somecondition">
  </sometag>   <!-- close the tag -->
</xsl:if>


Which is impossible to do, as you pointed out: it is not XML. And XSLT must be XML in the first place. It seems that you are trying to instruct the processor HOW something must be achieved. This is not what you should try. Just tell the processor WHAT you want it to output by what RULES (check out www.w3schools.com for a basic tutorial on this principle, or any xslt book).


We will need to see more of your code, or better, of what you want to output, because this is too little information. Something I can think of:

<xsl:template match="somematch">
  <xsl:choose>
  <xsl:when test="$a != $times" >
      <xsl:apply-templates select="somechild" mode="create-orOp" />
  </xsl:when>
  <xsl:otherwise>
     <xsl:apply-templates select="somechild" />
  <xsl:otherwise>
  <xsl:choose>
</xsl:template>

<xsl:template match="somechild"  mode="create-orOp">
   <xqx:orOp>
       <xqx:firstOperand>
            <xsl:apply-templates select="self::somechild" />
       </xqx:firstOperand>
   </xqx:orOp>
</xsl:template>

<xsl:template match="somechild">
   ... do something ...
</xsl:template>

The above code is one way to include/exclude the orOp + firstOperand as parents from some output. But it is likely not the best way, and I can think of many scenario's where the same is possible without the xsl:choose. But that depends on what you actually are trying to achieve.

Cheers,
-- Abel Braaksma
  http://www.nuntia.nl

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.