Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 4th, 2014, 09:51 AM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Angry match uncaught though declared in XSL

I've the below XML.


Code:
<para indent="no">
   <star.page>18</star.page> Further to same.
</para>
and when i run the below XSLT.


Code:
<xsl:template match="para">

    <xsl:value-of select="./node()[1][self::star.page]|./label/node()[1][self::star.page]"/>
    <div>
        <xsl:choose>
            <xsl:when test="./@align">
                <xsl:attribute name="class"><xsl:text>para align-</xsl:text><xsl:value-of select="./@align"/></xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
                <xsl:attribute name="class"><xsl:text>para</xsl:text></xsl:attribute>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:apply-templates/>
    </div>
</xsl:template>
When i run this, instead of printing <div class="para">18</div>, it is printing <div class="para"></div>

please let me know where am i going wrong and how can i fix this.

Thanks :( :(
Reply With Quote
  #2 (permalink)  
Old December 4th, 2014, 10:00 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

When I run it it outputs:

Code:
<div class="para">
   18 Further to same.
</div>
Therefore the issue is something about something you have not shown us, so we are unlikely to be able to help.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #3 (permalink)  
Old December 4th, 2014, 10:10 AM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
When I run it it outputs:

Code:
<div class="para">
   18 Further to same.
</div>
Therefore the issue is something about something you have not shown us, so we are unlikely to be able to help.
Hi Samjudson,
Thanks for the reply, this is taking as a regular text. I've added a div to get this number inside it. and here is the demo .

http://xsltransform.net/eiZQaF5/1.

Here you can see the difference.
Reply With Quote
  #4 (permalink)  
Old December 4th, 2014, 10:14 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No, That outputs exactly what I listed above, from what I can see.

You need to be a bit more specific in what output you are expecting I think, as we are clearly not understanding your requirements.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #5 (permalink)  
Old December 4th, 2014, 10:21 AM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
No, That outputs exactly what I listed above, from what I can see.

You need to be a bit more specific in what output you are expecting I think, as we are clearly not understanding your requirements.
First of all sorry for the entire confusion.

This is the final update, no more updates to my question, i mean i won't change it.

http://xsltransform.net/eiZQaF5/2

Here there is a div created <div class="x"> and the return value is <xsl:value-of select="./node()[1][self::star.page] or ./label/node()[1][self::star.page]"/>

Here the question is star.page is immediate child of para, so i think ./node()[1][self::star.page] is true, but the return value in <div class="x"> is false. I want to know where am i missing this part, i mean how to get this true
Reply With Quote
  #6 (permalink)  
Old December 4th, 2014, 10:34 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

So you don't want <div class="para">18</div> at all, you want 18<div class="para"></div>.

Try just using "*" instead of "node()". node() will match ANY node, including text nodes (of which a there will be three).

e.g. imagine your source xml looks like this:

Code:
<para indent="no"><text>
   </text><star.page>18</star.page><text> Further to same.
</text></para>
So node() is matching that first text node, which just contains whitespace. "*" matches only child ELEMENTS, and a text node is not considered to be an element.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #7 (permalink)  
Old December 4th, 2014, 10:42 AM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
So you don't want <div class="para">18</div> at all, you want 18<div class="para"></div>.

Try just using "*" instead of "node()". node() will match ANY node, including text nodes (of which a there will be three).

e.g. imagine your source xml looks like this:

Code:
<para indent="no"><text>
   </text><star.page>18</star.page><text> Further to same.
</text></para>
So node() is matching that first text node, which just contains whitespace. "*" matches only child ELEMENTS, and a text node is not considered to be an element.


Here starts the actual confusion.
with your suggestion(which i've tried previously), please have a look at this

http://xsltransform.net/gWmuiJ7

here if i use <xsl:apply-templates select="./*[1][self::star.page]" mode="first"/>, the output has a duplication(this is an error).

And if i use <xsl:apply-templates select="./node()[1][self::star.page]" mode="first"/>, the output that i get is what is required.(if i change * to node()).
Reply With Quote
  #8 (permalink)  
Old December 4th, 2014, 12:28 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

That is really ugly code. Use of disable-output-encoding and lots of html inside CDATA usually means you are trying to use XSLT in a way XSLT is not designed to be used.

It is not clear at all from the link you provide what you are attempting to do, especially as the HTML you are outputting is not actually valid XML any more (no <body> element, the </head> is followed by a <a> which is then followed by a closing </span> element?)

Your inclusion of process-instructions leads me to believe you want a machine to be able to process this output, therefore you need to consider what you are actually generating above carefully.

You need to get this down to the bare minimum that illustrates your basic requirements, so that we can easily reproduce the issue at our end and also provide the exact output you are expecting to see.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Call template with match tag doesn't copy values of passed param. sureshvadali XSLT 2 July 30th, 2012 04:44 AM
giving two conditions in match in xsl:key vidhiS XSLT 2 February 29th, 2008 05:40 AM
How to Only Match Elements that Equal an XSL Var? tclancy XSLT 1 April 21st, 2006 04:05 PM
xsl:template match 'overlapping' ? Kabe XSLT 1 February 25th, 2005 06:03 AM
help with xsl template match enT XSLT 9 September 24th, 2003 06:21 AM



All times are GMT -4. The time now is 10:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.