Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2006, 09:22 PM
Authorized User
 
Join Date: Dec 2004
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
 
Old August 24th, 2006, 10:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old August 24th, 2006, 12:05 PM
Authorized User
 
Join Date: Dec 2004
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
 
Old August 24th, 2006, 12:10 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old August 24th, 2006, 12:17 PM
Authorized User
 
Join Date: Dec 2004
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





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





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