Very simple XSLT string replacing question

Hi,
This is a really simple question for you guys, but it took me long, and i still couldn't solve it.
I just want to remove all spaces from a node inside an XML file.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<root insertedtime="2008-05-01T14:03:00.000+10:00" pkid="23421">
   <books>
      <book type='fiction'>
         <author>John Smith</author>
         <title>Book title</title>
         <year>2 0  0 8</year>
      </book>
   </books>
</root>in the 'year' node, the value should not contain any spaces, that's the reason why i need to remove spaces using XSLT. Apart from removing space, i also need to make sure that the 'year' node has a non-empty value. Here's the XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="//books/book[@type='fiction']">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:attribute name="id">101</xsl:attribute>
            <xsl:call-template name="emptyCheck">
                <xsl:with-param name="val" select="year"/>
                <xsl:with-param name="type" select="@type"/>
                <xsl:with-param name="copy" select="'true'"/>
            </xsl:call-template>
            <xsl:value-of select="translate(year, ' ', '')"/>
        </xsl:copy>
    </xsl:template>
    <!-- emptyCheck checks if a string is an empty string -->
    <xsl:template name="emptyCheck">
        <xsl:param name="val"/>
        <xsl:param name="type"/>
        <xsl:param name="copy"/>
        <xsl:if test="boolean($copy)">
            <xsl:apply-templates select="node()"/>
        </xsl:if>
        <xsl:if test="string-length($val) = 0 ">
            <exception description="Type {$type} value cannot be empty"/>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>The 'emptyCheck' function works fine, but the space replacing is not working, this is the result after the transform:
<?xml version="1.0" encoding="utf-8"?>
<root insertedtime="2008-05-01T14:03:00.000+10:00" pkid="23421">
   <books>
      <book type="fiction" id="101">
         <author>John Smith</author>
         <title>Book title</title>
         <year>2 0 0 8</year>2008</book>
   </books>
</root>The spaced year value is still there, the no-space year is added outside the 'year' tags'
anyone can help me, your help is extremely appreciated!
Thanks!

You should add a template for 'year' :<xsl:template match="year">
<year><xsl:value-of select="translate(.,' ','')"/></year>
</xsl:template>and remove the translate call in the 'book' template.
It would be better to add a 'priority' attribute at each template so it would be explicit which template to use because match="@*|node()" could be interpreted by another transform engine as the unique template to be used !

Similar Messages

  • Very simple, but not working Table to Flat File

    I'm new to ODI, but I am having too much difficulty in performing a very basic task. I have data in a table and I want to load the data to a flat file. I've been all over this board, all over the documentation, and all over the Googles, and I can not get this to work. Here is a run down of what I have done thus far:
    1. created a physical schema under FILE_GENERIC that points to my target directory
    2. created a logical schema that points to my new physical schema
    3. imported a test file as a model (very simple, two string columns, 50 chars each)
    4. set my parameters for my file (named columns, delimited, filename resource name, etc.)
    5. created a new interface
    6. dragged my new file model as the target
    7. dragged my source table as well
    8. mapped a couple of columns
    9. had to select two KMs: LKM - SQL to SQL (for the source) & IKM - SQL to File Append (for the target)
    10. execute
    Now, here is where I started hitting problems. This failed in the "load data" step with the following error:
    +7000 : null : java.sql.SQLException: Column not found: C1_ERRCODE+
    I found a note on the forum saying to change the "Staging Area Different From Target" setting on the Definition tab. Did that and selected the source table's schema in the dropdown, ran again. Second error:
    +942 : 42000 : java.sql.SQLException: ORA-00942: table or view does not exist+
    This occurred in the "Integration - insert new rows" step.
    The crazy thing is that in a step prior to this ("Export - load data"), the step succeeded and the data shows up in the output file!
    So why is ODI trying to export the data again? And why am I getting an ORA error when the target is a file?
    Any assistance is appreciated...
    A frustrated noob!
    Edited by: Lonnie Morgan (CALIBRE) on Aug 12, 2009 2:58 PM

    I found the answer. But still not sure why this matters...
    Following this tutorial, I recreated my mapping:
    [http://www.oracle.com/technology/obe/fusion_middleware/ODI/ODIproject_table-to-flatfile/ODIproject_table-to-flatfile.htm]
    I was still getting the same error. I reimported my IKM and found that the "Multi-Connections" box was unchecked before and now it was checked. I may have unchecked it in my trial & error.
    Anyway, after running the mapping again with the box checked, the extract to a file worked.
    So, I'm happy now. But, I am also perturbed with the function of the this checkbox and why it caused so much confusion within ODI.

  • A very very very simple question

    Hi guys,
    I have a very simple question and standard but I cant find anywhere...
    I have two dateTime variables, i need to calculate difference between this dates in days, thats it.
    I tried all functions and tried without success a Java Embed task but I couldnt retrieve this objects as java.util.Date so I couldnt calculate exactly the difference in days like this pure java code:
    (dataVencimento.getTime() - dataReferencia.getTime()) / 86400000L)
    can you help me this?

    Hi Jose
    Just see if these alternate approaches works. I know there may be lot like this and you may be lucky to find out simple out of box solution itself. If you want to solve this issue and move ahead, gives these approaches a shot.
    1. Create a very simple standalone WebService that takes 2 input date elements (can be of Date type or String type. If string type, convert to date in your java code). Create a simple operation like getDaysBetween(firstDate, secondDate). In the generated webservice impl class, use the java code apis (refer earlier link for usage), and get the difference. Return this value. NOW, invoke this WebService in your BPEL Process, and pass your 2 inputs (if the bpel payload elemetns are date object or string objects of date), and get output, and then use this output in your continuing bpel process.
    2. This approach, I did a long back. When we insert any expression using XPath, in that editor window on bottom right side, we see many categories and for each category we see list of functions we can use, like for String, we can use concat etc. I vaguely remember reading somewhere, that we can add our own custom functions also in this section. So explore this direction and see if you can add your own function and then use that fucntion with your 2 input dates.
    I have not given solution to your problem, but may be these directions can help you move ahead. Or something along these lines.
    Thanks
    Ravi Jegga

  • A very simple question..Very Urgent

    HI,
    I have a very simple question.I am able to set up the client authentication as well as server authentication. Now do i need to authenticate (both server as well as client auth.) for every request i send to the server on https...i think it should be like that it should authenticate only for the first time and for the next upcoming requests in same session should not require any server or client authentication.. i think as it happens in browsers..
    what is the fact actually??..can somebody put some light...right now in my case it is authenticating for every requests..
    This is what i have done..
    /****constructor part********/
    // and tm are arrays of keymanagers and trustmanagers for client keystore and truststore
    sslContext.init(km, tm, null);
    HttpsURLConnection.setDefaultSSLSocketFactory(ssf);
    HttpsURLConnection.setDefaultHostnameVerifier(new MYHostNameVerifier());
    /****Method to send the request and response*********/
    urlConn = (HttpsURLConnection)url.openConnection();
    urlConn.setDoInput(true);
    urlConn.setDoOutput(true);
    OutputStream os = urlConn.getOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(someobject);
    oos.flush();
    InputStream is1 = urlConn.getInputStream();
    ObjectInputStream ois = new ObjectInputStream(is1);
    SomeObject retObj = null;
    retObj = (SomeObject)ois.readObject();
    ois.close();
    System.out.println("Get String>>>>> "+retObj.getString());
    I am creating the object of this class..and calling the method again and again for sending requests and response..so i think handshake everytime i call the method...what i want is that handshake should happen for the first time and for the next requests no handshake or certificates should be checked or processed..
    is it possible ..how..what i need to do for that..
    please help me in this..
    Akhil Nagpal

    Hi,
    how could I achieve SSL Session Resumption using HttpsURLConnection.
    Thanks.

  • This is a very simple question,but I don't know.Please me.Thank you!

    I am a Chinese student in a university.I have a very simple question to ask.
    I have writed a EJB module,and I have deployed to Weblogic8.1 successfully.
    1.Now I want to write a client program.Is it necessary that the client program is packaged in the EJB package.For example ,the EJB package is Beans,is "package Beans " or "import Beans.*" necessary in my client program.
    2.If I only know the EJB interfaces,that means the EJB module is writed by other programer.I want to know how I can write the client program.How can I call EJB module's method writed by other programer.Could you give me a simple example?
    Thank you very much.

    I have writed a EJB module,and I have deployed to
    Weblogic8.1 successfully.:-)
    1.Now I want to write a client program.Is it
    necessary that the client program is packaged in the
    EJB package.For example ,the EJB package is Beans,is
    "package Beans " or "import Beans.*" necessary in my
    client program.You need not package your client with the EJB. It can be a JSP/servlet or a stand-alone application.
    2.If I only know the EJB interfaces,that means the
    EJB module is writed by other programer.I want to
    know how I can write the client program.How can I
    call EJB module's method writed by other
    programer.Could you give me a simple example?
    import java.util.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import examples.*;
    class TestEJBHello {
        public static void main(String[] args) {
            Context context   = null;
            Object object     = null;
            // Hashtable for environment properties.
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            env.put(Context.PROVIDER_URL, "t3://localhost:7001");
            HelloHome home            = null;
            HelloWorld hello          = null;
            try {
                context     = new InitialContext(env);
                object      = context.lookup("HelloWorldTest");
                System.out.println(" JNDI Looked up >>> " +object);
                home        = (HelloHome)PortableRemoteObject.narrow(object, HelloHome.class);
                hello       = home.create();
                System.out.println(hello.hello());
            } catch(Exception e) {
                e.printStackTrace();
            } finally {
                close(context);        // Closes the initial context.
        private static void close(Context context) {
            try {
                context.close();
                System.out.println("*** Context closed. ***");
            } catch (NamingException namingException) {
                namingException.printStackTrace();
            } catch(Exception exception) {
                exception.printStackTrace();
    }Here's a sample client app code I use for a HelloWorld EJB. You need to have a EJB client JAR containing the home and remote interfaces in the classpath during compile time and runtime.
    x

  • Very simple question from a beginner

    I am currently doing a little exercise, but I ran into a problem. I have written a class that supports operations on rational number. The fields are two long variables, one each that stores the numerator and denominator.
    I have made add, subtract, multiply, and divide methods...
    1. what I need help in is: beingh able to store the rational number in reduced for, with the denominator always positive
    2. constructing a toString method, equals method, and compareTo method.
    3. it also says "make sure the toString method correctly handles the case in which the denominator is zero by throwing an exception.
    I have been working on this for a long time now, an I am stuck at this point.
    I know this will be very simple for you guys and gals, but I am a beginner. Please offer some input, advice, and/or some code to help me get past this problem.
    Thanks so much,
    Jason

    ok, here is what I have so far
    public class Rational {
         public long num, den;
         public Rational(long n,long d) {
              this.num = n;
              this.den = d;
         public static void main(String args[]) {
              Rational r = new Rational(1,2);
              Rational s = new Rational(3,4);
              Rational rmuls = r.multiply(s);
              Rational rdivs = r.divide(s);
              Rational radds = r.add(s);
              Rational rsubs = r.subtract(s);
              r.print();
              s.print();
              rmuls.print();
              rdivs.print();
              radds.print();
              rsubs.print();
         public void print(){
              System.out.println(this.num+ "/" +this.den);
         public Rational multiply(Rational t){
              long n;
              long d;
              n = this.num*t.num;
              d = this.den*t.den;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational divide(Rational t){
              long n;
              long d;
              n = this.num*t.den;
              d = this.den*t.num;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational add(Rational t){
              long n;
              long d;
              n = (t.den*this.num)+(t.num*this.den);
              d = t.den*this.den;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational subtract(Rational t){
              long n;
              long d;
              n = (t.den*this.num)-(t.num*this.den);
              d = t.den*this.den;          
              Rational answer = new Rational(n,d);
              return answer;
         //public int compareTo (Rational t)??????

  • Very simple question, how do you configure windows 8.1 to use a SF card as the default install location for software applications?

    Very simple question, how do you configure windows 8.1 to use a SD card / external drive as the default install location for software applications? Primarily interested in apps installed from the windows store. This should be available in the settings
    charm within the windows store. This must have been overlooked in the development of windows 8.1 or is a bug.
    Regards, Bill
    * update
    I've tried modifying this key and the path:
    “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx”
    http://answers.microsoft.com/en-us/windows/forum/windows_8-windows_store/how-do-you-install-apps-in-windows-8-from-the/c4fbe2a8-fd3d-41c1-b9a6-6f881eed374f
    Also tried using symlinks as detailed here:
    http://social.technet.microsoft.com/Forums/windows/en-US/8eee52c2-db0f-4032-8c72-7cd999e8b41a/windows-8-apps-installing-to-secondary-drive?forum=w8itprogeneral

    Here's some links I've used to try to figure this out:
    http://social.technet.microsoft.com/Forums/windows/en-US/2dfc0cd9-7d1b-41de-abce-e03fb6a5a383/metro-apps-not-working-in-windows-8-pro-x64-after-moving-users-and-programdata-folders?forum=w8itproinstall
    http://social.technet.microsoft.com/Forums/windows/en-US/8eee52c2-db0f-4032-8c72-7cd999e8b41a/windows-8-apps-installing-to-secondary-drive?forum=w8itprogeneral
    http://social.technet.microsoft.com/Forums/windows/de-DE/f5e33ac9-beab-4b99-b3ca-7cb5e6f415e4/how-do-you-change-metro-apps-default-install-location?forum=w8itprogeneral
    Regards, Bill
    The registry method does not work with 8.1.  I found this out the hard way.  Doing it on 8.1 will leave you reinstalling the OS if you didn't do a SRP beforehand.

  • VERY SIMPLE QUESTION REGARDING UML DIAGRAMS IN JDEVELOPER

    Hello there,
    I have a very simple question. I want to know how I can convert a class diagram that I have created in jdeveloper into a jpg image so I can put in word. When I try exporting it only has the uml to xmi option
    Does anyone have a suggestion?

    Hi,
    Right mouse click on the class diagram,
    than click publish diagram on the context menu
    and save as jpg where ever you want...
    Boris

  • HT4753 I have a very simple question: how do I view where Lion has autosaved my current version to (without the convoluted route of using finder)? In days gone by i'd simply use the save as function to see where it was being saved.

    I have a very simple question: how do I view where Lion has autosaved my current version to (without the convoluted route of using finder)? In days gone by i'd simply use the save as function to see where it was being saved.

    It's actually even easier than using Save As to see the full path to the currently open document. Just do a "Secondary click" on the document title in its window's title bar.
    Like you, I relied upon Save As my whole life to check a file's location and considered it a must-have capability. Turns out it's even faster to use the single-click method to reveal the full path to the open document. It displays the entire path to the current document starting from the level of your Mac, and works for files stored on drives as well as iCloud.
    If you're not sure how to do a secondary click, go into System Preferences, select Trackpad, Point & Click to find the current preference for secondary click on your Mac. If you happen to have a mouse with more than one button, it's probably the right button. As a trackpad user, I check the box to "Click or tap with two fingers," so a simple two finger tap on the title of an open document reveals its full path. This feature actually has been around for a very long time.
    Note that this is not the same thing as the Autosave and Versions menu, which is exposed using a little drop down triangle to the right of the title. There is no visual clue for the presence of this feature - you just have to know it's there, probably because this feature goes all the way back to pre-OS X days.

  • Very simple jstl question

    I for the life of me have not been able to find the answer to this very simple question, googling and looking at various documentation. What is the difference between accessing properties using $ or #? Is there a difference?
    Thanks

    Read on this excellent explanation about the unified EL: http://java.sun.com/products/jsp/reference/techart/unifiedEL.html

  • Very Simple C question - reading input parameters/flags... [SOLVED]

    This is an extremely simple question. Please forgive me for being a noob. I am writing an application in C (with GCC) called GAPE and need to be able to pass it parameters through a shell script (/usr/bin/gape) that can determine how it runs. To start with easy stuff, I want the end-user to be able to type "gape -V" to output the version of the program. How do I do that? I understand that I need to put the shell script in /usr/bin...where should I put the actual gcc-compiled gape application? Or do I even need a shell script? Can I just put the GAPE binary in /usr/bin and pass parameters to it directly? If so, how do I do that in C? Any help is greatly appreciated.
    Last edited by tony5429 (2008-03-10 12:00:21)

    include <stdio.h>
    main(int argc, char *argv[])
    int i;
    for(i = 1; i < argc; i++) //argc = the number of arguments
    printf("param nr %d: %s\n", i, argv[i]); // argv[i] contain the arguments, with 0 being the program name (anyone may correct me here)
    [jaqob@p238 c++-egna]$ ./a.out 1 2 3
    param nr 1: 1
    param nr 2: 2
    param nr 3: 3
    [jaqob@p238 c++-egna]$ ./a.out -h -V -zxvf
    param nr 1: -h
    param nr 2: -V
    param nr 3: -zxvf
    A very simple program that prints the parameters
    And yes, you can put the program in /usr/bin/ without a shellscript
    Last edited by JaQoB (2008-03-05 18:09:34)

  • Can anyone answer a very simple question for me ive heard the apple was giving a free iphone 4 or 4s bumper away is there any truth to that?

    can anyone answer a very simple question for me ive heard the apple was giving away iphone 4 or 4s bumpers is there any truth to that?

    Not any more, no. There was a free bumper program back when the iPhone 4 originally came out. It has long since expired.

  • Very simple CVI-progra​m and question

    Hi
    I have just started working with CVI and, as far as I can see, the principle behind the interaction between various elemements is similar as in Delphi. I have made a very simple example (User Interface Application), containing a square command button and a numeric. My idea was to push the button, whereafter the NUMERIC-control displays some number. However, I can't seem to figure out how to construct change the function that is executed when pushing the button. I tried double-clicking, right-clicking, etc.., but I couldn't figure it out. I hope my question makes sense.
    Solved!
    Go to Solution.
    Attachments:
    untitled.JPG ‏11 KB

    I searched for litterature, but only found the Programmer Reference Manual (http://www.ni.com/pdf/manuals/323643a.pdf). The litterature you suggest seems very relevant, I'll take a look at it. Thanks.

  • Real simple xslt problem/question

    Hi, i have a real simple xslt problem but i just cant figure out how to do it by looking at various examples on the net. i have a xml document and in it are some elements with a "result" tag name. i want to use xslt to reproduce exactly the same xml document except with an attribute called "id" added to those elements with a "result" tag name. i'm sure that theres a simple solution to it but i just cant figure it out. any helps greatly appreciated, thanks

    Start with the XSLT identity transform (I don't have it handy and it's fairly long, but you should be able to google it up). Add this:<xsl:template match="result">
      <result id="">
        <xsl:apply-templates>
      </result>
    </xsl:template>

  • Very simple question from a rookie

    Hi,
    I don't know how sequences work in OWB.
    I have a very simple mapping:
    1 (not empty) source table, 1 (empty) target table, 1 sequence.
    Source and destination are connected.
    The sequence.nextval is connected to the primary key. sequence.currval is not connected.
    When I run the debug mode an error occurs: "Could not find data for all sources and target ...". The "Test Data" shows that OWB has not found data for the sequence.
    Help!

    I use 10gR2 and OWB 10.2
    The tables and the sequence are deployed. They are in the database.
    There's something strange about this:
    Starting ("Start...") works.
    The debugging does not work.
    Problem nearly solved ...
    Message was edited by:
    user517859

Maybe you are looking for

  • Reg: Automating Miscellaneous Issue

    Hello Everybody, I have one query, i am presently working on interface. i have a requirement of automating the Miscellaneous Issues periodically. i want some of my items to be issued out of oracle automatically at regular intervals. Is there any Poss

  • Suppliers Aging Report layouts - Date in US format

    Hi all I am running the above layout.  The Date field for the document date is a system variable but it displays as US format.  How do I get it to display UK?  Thanks! Lorna

  • Haven't received refunds

    I have contacted Report A Problem about getting refunds from apps that don't work and I haven't received those refunds yet.

  • Venn diagram in BEX

    Is venn diagram possible in BEX For example Total no of vendors GGn = 100                       Total no of vendors DHR =50                        Common vendors between these 2 plants is = 20 Then I want the venn diagram for this

  • What's with my Macbook's internet?

    I have a problem with my internet not working on my macbook pro, for a week now. And  my internet at home works fine because i was able to connect with my ps3, I went to a public hotspot and my wifi on my macbook still didnt work. I think i know what