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 | 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 August 23rd, 2006, 09:22 PM
Authorized User
Points: 138, Level: 2
Points: 138, Level: 2 Points: 138, Level: 2 Points: 138, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: McHenry, IL, .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default HOW TO: xlate attribute values?

Hi,
Using XSLT V1.0, I would like to know how to translate substrings in an element's attribute.

The following example should clarify what I am looking for. What does the template 'translate-ops' (see below) need to look like to produce an XSLT Result:

{
    if(($x > $y) && (($x + $y) < 100) || ($x < 0)){return;}
}

TNX

==================== XML =======================

<?xml version='1.0' encoding='utf-8' ?>
<program xmlns:p="http://www.my.org/xml/lang">
    <p:if test="($x GT $y) AND (($x + $y) LT 100) OR ($x LT 0)">
        <p:return/>
    </p:if>
</program>
================================================

==================== XSLT ======================

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0"
    xmlns:p="http://www.my.org/xml/lang"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method='html' version='1.0' encoding='UTF-8' indent='no'/>


  <xsl:variable name="OP_EQ" select="'EQ'"/>
  <xsl:variable name="OP_GE" select="'GE'"/>
  <xsl:variable name="OP_GT" select="'GT'"/>
  <xsl:variable name="OP_LE" select="'LE'"/>
  <xsl:variable name="OP_LT" select="'LT'"/>
  <xsl:variable name="OP_AND" select="'AND'"/>
  <xsl:variable name="OP_OR" select="'OR'"/>


  <xsl:variable name="X_EQ" select="'=='"/>
  <xsl:variable name="X_GE" select="'&gt;='"/>
  <xsl:variable name="X_GT" select="'&gt;'"/>
  <xsl:variable name="X_LE" select="'&lt;='"/>
  <xsl:variable name="X_LT" select="'&lt;'"/>
  <xsl:variable name="X_AND" select="'&amp;&amp;'"/>
  <xsl:variable name="X_OR" select="'||'"/>


    <xsl:template match="/">
      <html>
      <body>
      <h3>XSLT Result</h3>
      <textarea cols="80" rows="4">
        <xsl:apply-templates select="*"/>
      </textarea>
      </body>
      </html>
    </xsl:template>

    <xsl:template match="program">
      <xsl:value-of select="'{'"/>
      <xsl:apply-templates/>
      <xsl:value-of select="'}'"/>
    </xsl:template>

    <xsl:template match="p:if">
        <xsl:value-of select="'if('"/>
        <xsl:call-template name="translate-ops">
            <xsl:with-param name="op-expr" select="@test"/>
        </xsl:call-template>
        <xsl:value-of select="')'"/>
        <xsl:value-of select="'{'"/>
        <xsl:apply-templates select="*"/>
        <xsl:value-of select="'}'"/>
    </xsl:template>

    <xsl:template match="p:return">
      <xsl:value-of select="'return;'"/>
    </xsl:template>


    <xsl:template name="translate-ops">
        <xsl:param name="op-expr"/>
        <xsl:value-of select="$op-expr"/>
    </xsl:template>

</xsl:stylesheet>

================================================


Philibuster
__________________
Philibuster
Reply With Quote
  #2 (permalink)  
Old August 24th, 2006, 10:51 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

See

http://www.dpawson.co.uk/xsl/sect2/replace.html

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old August 24th, 2006, 12:05 PM
Authorized User
Points: 138, Level: 2
Points: 138, Level: 2 Points: 138, Level: 2 Points: 138, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: McHenry, IL, .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael, thanks for your reply.

Which method from this site are you advocating as a solution?


Philibuster
Reply With Quote
  #4 (permalink)  
Old August 24th, 2006, 12:10 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I wouldn't advocate any solution from that site, I would advocate XSLT 2.0.

Seriously, I don't know anything about your criteria for choosing one solution rather than another, so how could I recommend anything? I just point you to the information.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old August 24th, 2006, 12:17 PM
Authorized User
Points: 138, Level: 2
Points: 138, Level: 2 Points: 138, Level: 2 Points: 138, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: McHenry, IL, .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK, when I looked at the site, none of the solutions looked like what I wanted. Was there something I missed? BTW, I'm stuck with XSLT V1.0 like it or not.

Philibuster
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
Please help, Combine two like attribute values mikhen7 XSLT 4 July 10th, 2006 02:25 PM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
how to get values depending on the attribute vidhya XSLT 1 July 8th, 2005 03:55 AM
Matching of attribute values gb XSLT 2 February 10th, 2004 04:12 AM
different values with the same attribute name srini XSLT 0 January 21st, 2004 05:21 AM



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


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