Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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 11th, 2008, 01:39 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT - fetching element value without getting the

Hi ,

I am using XSLT as below

<?xml version="1.0" ?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:js="javascript:code"

xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:output method="xml" doctype-public="string" />
    <msxsl:script implements-prefix="js" language="javascript">
        var i = 0;
        function getnumber()
        {
            return i++;
        }
    </msxsl:script>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:attribute name="id"><xsl:value-of select="js:getnumber()"></xsl:value-of></xsl:attribute>
      <xsl:attribute name="xpathdata"><xsl:for-each select="ancestor::*">-&gt;

<xsl:value-of select="@name" /> [<xsl:number />]</xsl:for-each>-&gt;
/* I have problem with the below statement Actually name() fetches the node name
but i want the value of the node. So, If i uses <xsl:value-of select="." /> It fetches the concated text of current node +

nodes all the child nodes the current node. But I want value of the current node only. One solution can be using the element

name like <xsl:value-of select="nodename" /> but the problem is this code is generic and don't have any fixed element name.
Can anybody suggest some solution so that i can fetch the value of that node only.
*/
<xsl:value-of select="name()" />
[<xsl:number />]</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>Regards,

Sam

 
Old August 11th, 2008, 03:02 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

I can't unfortunately tell you the answer to your question, because I have no idea what your input XML looks like.

If you show us your input XML then we can probably answer you question.

/- Sam Judson : Wrox Technical Editor -/
 
Old August 11th, 2008, 03:16 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<sensitiveobjectdetails xmlns="http://www.soa.net/sample.xsd">
  <wellknownobjects>
    <transaction name="ME21" applicationname="SA">
      <description>Create Purchase Order</description>
      <auth name="M_BEST_BSA" applicationname="SAP">
        <description>Document Type in Purchase Order (CM)</description>
        <attribute name="ACTVT" operator="and">
          <description>Activity</description>
          <attributevalues isliteral="false" isparameter="false">
            <value>02</value>
            <description>Change</description>
          </attributevalues>
          <attributevalues isliteral="false" isparameter="false">
            <value>01</value>
            <description>Create or Generate</description>
          </attributevalues>
        </attribute>
      </auth>
    </transaction>
  </wellknownobjects>
  <operator>and</operator>
</sensitiveobjectdetails>

 
Old August 11th, 2008, 03:19 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

If you want text nodes of the current node only then try using "text()" rather than "."

/- Sam Judson : Wrox Technical Editor -/
 
Old August 11th, 2008, 03:30 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thank you. The problem got resolved by using "text()" rather then using "." in <xsl:value-of select= .

Regards,

Sam





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML element with delimited values and XSLT Clark Kent XSLT 15 May 7th, 2008 10:10 AM
Urgent:XSLT element value selection and condition amhicraig XSLT 1 December 4th, 2007 07:57 PM
Element value type in XSLT 1.0 NEO1976 XSLT 9 February 13th, 2007 11:11 AM
Copy element into complexType in XSLT 2BOrNot2B XSLT 3 December 20th, 2006 09:09 AM
Write XML element into textbox with XSLT tcstom XSLT 4 July 5th, 2006 04:08 AM





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