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 February 23rd, 2007, 01:18 PM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Going up a level from current node.

Forgive me if this question sounds easy, but I am not all the way through my XSLT 2.0 book yet (actually only on chapter 3 style sheet structure).

I have the following:

Input (xml doc):

<CPIMessage key="EPO" version="1.0" xmlns="http://www.openfox.com" xmlns:n-pro="http://cjis.fbi.gov/ncic/protectionorder/1.0.0" xmlns:ncic="http://cjis.fbi.gov/ncic/1.0.0" xmlns:cjis="http://cjis.fbi.gov/1.0.0" xmlns:jxdm="http://www.it.ojp.gov/jxdm/3.0.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openfox.com por.xsd">
    <Header>
        <Initiator>INISP00C2</Initiator>
        <Destination>IDACS</Destination>
        <ControlField>TESTPOR004</ControlField>
    </Header>



Portion of Style sheet


 <xsl:template match="cpi:Header">
  <xsl:element name="HDR">
   <xsl:element name="MKE">
     <xsl:value-of select="$key"/>
   </xsl:element>

   <xsl:element name="ORI">
    <xsl:value-of select="cpi:Initiator"/>
   </xsl:element>
   <xsl:for-each select="cpi:Destination">
    <xsl:element name="DST">
     <xsl:value-of select="."/>
    </xsl:element>
   </xsl:for-each>
   <xsl:element name="CTL">
    <xsl:value-of select="cpi:ControlField"/>
   </xsl:element>
  </xsl:element>
 </xsl:template>

My output

<HDR><MKE/><ORI>INISP00C2</ORI><DST>IDACS</DST><CTL>TESTPOR004</CTL></HDR>

My Problem I am trying to get the MKE element of the CPIMessage tag.
I was unsure of what to do you can see from the above code on what I tried. I wasn't sure if there is a way to go up to the root node from the current context node. All of the other output works great, I just can't get the data for the mke.

Thanks for your time.

 
Old February 23rd, 2007, 01:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I imagine you want

<xsl:value-of select="../@key"/>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 23rd, 2007, 01:35 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

to get to a parent use ../
for grandparent ../../ and so on.

 
Old February 23rd, 2007, 01:55 PM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you to both of the responders.

Just a quick question the ../

The syntax has to deal with the Xpath correct? Trying to place of this together in my head.

 
Old February 23rd, 2007, 03:06 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

here is a quick reference:

http://www.w3schools.com/xpath/xpath_syntax.asp








Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare current value with previous parent node ratjetoes XSLT 2 July 17th, 2008 06:15 AM
Please help to check the current node... darshil XSLT 1 May 9th, 2007 02:42 AM
Position of a node outside current context QuickSilver002 XSLT 2 April 19th, 2007 02:07 PM
Copy all contents except current node in XSLT 2BOrNot2B XSLT 2 December 19th, 2006 06:44 PM
"for-the-current-node" instead of "for-each" ? webhead XSLT 2 August 25th, 2006 02:55 PM





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