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 October 13th, 2010, 04:27 AM
Authorized User
 
Join Date: Oct 2010
Posts: 25
Thanks: 8
Thanked 0 Times in 0 Posts
Default why xsl:value-of dosen't give out any output

Hello,

I have the following xml file
Code:
<?xml version="1.0" encoding="utf-8"?>
<be:byggesak  identifier="string" xmlns:be="http://www.be.no/xml/ns/byggesak" xmlns:iso3166="http://www.unece.org/etrades/unedocs/repository/codelists/xml/CountryCode.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.be.no/xml/ns/byggesak file:///X:/Projects/BYGGS%C3%98K/11217%20ByggS%C3%B8k%20bygning%20v.3.0/WebServices/internal_xsd_byggesak/byggesak_0_3.xsd">
    <be:soknadid>soknad_ehsan1</be:soknadid>    
    <be:saksid be:eier="string" />
    <be:byggesaksprosess>
      <be:soknadendringtillatelse>
        <be:endringansvarsrett>true</be:endringansvarsrett>
        <be:endringavansvarligsoker>true</be:endringavansvarligsoker>
        <be:endringdispensasjon>true</be:endringdispensasjon>
        <be:endringareal>true</be:endringareal>
        <be:endringplassering>true</be:endringplassering>
        <be:endringformal>true</be:endringformal>
        <be:endringbruk>true</be:endringbruk>
        <be:endringavtiltak>flase</be:endringavtiltak>
        <be:endringannet> true</be:endringannet>
        <be:beskrivelse>be:beskrivelse</be:beskrivelse>        
      </be:soknadendringtillatelse>
....
...
</be:byggesak>
I am trying to change the format of this using XSLT. so I have this code
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" exclude-result-prefixes="xs xdt err fn"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:fn="http://www.w3.org/2005/xpath-functions"
                xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
                xmlns:err="http://www.w3.org/2005/xqt-errors"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:iso3166="http://www.unece.org/etrades/unedocs/repository/codelists/xml/CountryCode.xsd"
                xmlns:be="http://www.be.no/xml/ns/byggesak"
                xsi:schemaLocation="http://www.be.no/xml/ns/byggesak file:///O:\byggsok\svn\XMLConverter\XSLT\Version0_3To2_0Transformation\Version0_3To2_0Transformation\Schemas\old\byggesak_0_3.xsd">

  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <xsl:apply-templates/> 
  </xsl:template>
  <!-- byggesak-->
  <xsl:template match="be:byggesak">
    <!--create the element with its attributes-->
    <xsl:element name="be:byggesak">
      <xsl:attribute name="soknadid">
        <xsl:value-of select="be:soknadid"/>
        <!-- get the value of the soknadid element and put it here -->
      </xsl:attribute>
      <xsl:attribute name="byggesaksid"/>
      <xsl:attribute name="soknadstype"/>

      <!-- create sak element and search for other elements -->
      <xsl:element name="be:sak">
        <!-- since soknadid and saksid aren't needed any more, it will just jump to byggesaksprocess -->
        <xsl:apply-templates />
      </xsl:element>
    </xsl:element>
  </xsl:template>

  <!-- byggesaksprocess and its children-->

  <xsl:template match="be:byggesaksprosess">
    <xsl:element name="be:soknad">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <!--START byggesaksprosess/soknadendringtillatelse-->
  <xsl:template match="be:soknadendringtillatelse">
    <xsl:element name="be:endringavtillatelse">
      <xsl:apply-templates/>
      <xsl:element name="kommunenssaksnummer"/>
      <xsl:text>&#xa;</xsl:text><!--new line, just for the looks;-) -->
    </xsl:element>
  </xsl:template>

  <xsl:template match="be:beskrivelse">
    <xsl:element name="be:beskrivelse">
      <xsl:value-of select="be:beskrivelse"/>
    </xsl:element>
  </xsl:template>
....
....
...
I have done this for all the nodes and their children. My problem is the <xsl:value-of > element doesn't give me any output, beside the value of the attribute I've created? I don't understand why this happens. As far as I have read it should print out the value of the select node as a string. so why isn't it working here?
This is the output:
Code:
<?xml version="1.0" encoding="utf-8"?>
<be:byggesak soknadid="soknad_ehsan1" byggesaksid="" soknadstype="" xmlns:be="http://www.be.no/xml/ns/byggesak">
  <be:sak>
  soknad_ehsan1  

    <be:soknad>
      <be:endringavtillatelse>
        <be:endringansvarsrett></be:endringansvarsrett>
        <be:endringavansvarligsoker></be:endringavansvarligsoker>
        <be:endringdispensasjon></be:endringdispensasjon>
        <be:endringareal></be:endringareal>
        <be:endringplassering></be:endringplassering>
        <be:endringformal></be:endringformal>
        <be:endringbruk></be:endringbruk>
        
        <be:endringannet></be:endringannet>
        <be:beskrivelse></be:beskrivelse>        
      <kommunenssaksnummer />
</be:endringavtillatelse>
      <be:igangsettingstillatelse>
            <be:delsoknad>
                
                <be:kommentar />
            <be:kommunenssaksnummer /></be:delsoknad>
            <be:delsoknad>
                <be:delavtiltaket />
....
....
....
I must admit that I am not a xslt programmer, work with C,C# and JAVA most of the time.
one other question
I am processing the soknadid node as an attribute which works, but I still its output, how can I skip certain nodes that I don't want to process.

cheers,
es

Last edited by ehsansad; October 13th, 2010 at 04:36 AM..
 
Old October 13th, 2010, 04:39 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I assume you mean this bit here:

Code:
<xsl:template match="be:beskrivelse">
    <xsl:element name="be:beskrivelse">
      <xsl:value-of select="be:beskrivelse"/>
    </xsl:element>
  </xsl:template>
Your problem is the xsl:value-of is asking for a subelement called be:beskrivelse - but you are already IN the be:beskrivelse element, which I assume has no child elements. What you probably want is something like this:


Code:
<xsl:template match="be:beskrivelse">
    <be:beskrivelse><xsl:value-of select="."/></be:beskrivelse>
  </xsl:template>
If however all you are doing is copying the entire element, then the following is simpler:


Code:
<xsl:template match="be:beskrivelse">
    <xsl:copy-of select="."/>
  </xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
ehsansad (October 13th, 2010)
 
Old October 13th, 2010, 05:00 AM
Authorized User
 
Join Date: Oct 2010
Posts: 25
Thanks: 8
Thanked 0 Times in 0 Posts
Default

Thank You. the "." is working forme. The use of copy-of give me additonal information , which are the namespaces inside my tags so the result will be something like
Code:
<be:beskrivelse xmlns:iso3166="http://www.unece.org/etrades/unedocs/repository/codelists/xml/CountryCode.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">be:beskrivelse</be:beskrivelse>
don't know why? is it possible to add these two ns to the root?

-es
 
Old October 13th, 2010, 08:15 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Yes, just add them to the root element.

Note how I didn't use <xsl:element> to create the element. It is much simpler to create elements without this, unless the name of the element is in some way dynamic.

Code:
<xsl:template match="be:byggesak">
    <!--create the element with its attributes-->
    <be:byggesak soknadid="{be:soknadid}" byggesaksid="" soknadstype="" 
      xmlns:iso3166="http://www.unece.org/etrades/unedocs/repository/codelists/xml/CountryCode.xsd" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    ...
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL:output method="text" Pankaj C XSLT 4 August 2nd, 2007 10:05 AM
Chart Server dosen't send message chenglong BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 15 January 24th, 2007 03:12 PM
XSL html output problem aiyer0912 XSLT 11 November 8th, 2006 07:19 AM
xsl:element not on its own line in output EstherMStrom XSLT 3 February 26th, 2005 06:08 AM
PDF output problem using XSL pulavarthi XSLT 1 November 6th, 2003 05:41 AM





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