Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 21st, 2007, 05:38 AM
Friend of Wrox
Points: 718, Level: 10
Points: 718, Level: 10 Points: 718, Level: 10 Points: 718, Level: 10
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default XML data extraction

Hi,

Version 1.0

I have been asked to refer this to the XSLT site.

I need to extract '0006509602/01' from the following code (See the OrderLine/LineReference section).

[u]XML</u>
Code:
<QQQOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://QQQ.com/QQQXML/Schemas/v3_0_1/QQQOrd.xsd" OrderType="Standalone Order" DocumentType="New">

  <F4FDocumentHeader>
    <SchemaVersion>3</SchemaVersion>
    <SchemaStatus>Approved</SchemaStatus>
    <DocumentCreated DateTimeType="Document Created">20070315 09:32</DocumentCreated>
    <DocumentTrackingId>56709</DocumentTrackingId>
    <DocumentRevisionNumber>1</DocumentRevisionNumber>
    <SourcePartnerID>AT</SourcePartnerID>
    <SourceDivisionID>KA</SourceDivisionID>
    <DestinationPartnerID>ASATST</DestinationPartnerID>
  </F4FDocumentHeader>

  <OrderHeader>
  .... 
  </OrderHeader>

  <TransportDetails>
  ....
  </TransportDetails>
 
  <OrderLine LineNumber="1">
    <LineReference ReferenceType="Contract Number" AssignedBy="Buyer">0006509602/01</LineReference>
    <LineReference ReferenceType="Contract Number" AssignedBy="Supplier">ppersupref</LineReference>
    <ProductReference ReferenceType="Assigned By Buyer">496500</ProductReference>
    <ProductDescription Type="Defined by Buyer">REGULATOR 1</ProductDescription>
    <ProductValues>
      <Quantity QuantityType="Order Quantity" QuantityUOM="Unit">1000</Quantity>
      <UnitPrice PriceUOM="Unit">0.59</UnitPrice>
    </ProductValues>
  </OrderLine>

</QQQOrder>
I have tried various methods to extract it, but so far, have only returned blanks.

[u]XSLT</u>
Code:
<xsl:for-each select=".//OrderLine/@LineNumber">
  <xsl:element name="OrderLine">
    <xsl:attribute name="LineNumber"><xsl:value-of select="position()"/></xsl:attribute>            
      <xsl:element name="LineReference">
        <xsl:attribute name="ReferenceType">Contract Number</xsl:attribute>                
          <xsl:attribute name="AssignedBy">Buyer</xsl:attribute>
            <xsl:value-of select="../LineReference[@ReferenceType='Contract Number' and @AssignedBy='Buyer']"/>      
      </xsl:element>
  </xsl:element>
</xsl:for-each>
The above 'value-of select' is ok for One (1) OrderLine, but..... NOT in the case where there are several.

I have tried to use the following but it returns blank:
Code:
<xsl:value-of select=".//OrderLine[@LineNumber='position()']/LineReference[@ReferenceType='Contract Number' and @AssignedBy='Buyer']"/>
Thanks in advance,



Neal

A Northern Soul
__________________
Neal

A Northern Soul
Reply With Quote
  #2 (permalink)  
Old March 21st, 2007, 06:12 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Okay, personally I would use a template rather than a for-each and I'm still unsure why you're using position() rather than the actual @LineNumber but here's my effort, I have changed the select so that it matches OrderLine rather than @LineNumber which makes it easier to select the needed data, I have used literal elements rather than create them with xsl:element and xsl:attribute.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/QQQOrder">
    <data>
      <xsl:for-each select="OrderLine[@LineNumber]">
        <OrderLine LineNumber="{position()}">
          <LineReference ReferenceType="Contract Number" AssignedBy="Buyer">
            <xsl:value-of select="LineReference[@ReferenceType='Contract Number' and @AssignedBy='Buyer']"/>
      </LineReference>
    </OrderLine>
      </xsl:for-each>
    </data>
  </xsl:template>
</xsl:stylesheet>
--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old March 21st, 2007, 06:27 AM
Friend of Wrox
Points: 718, Level: 10
Points: 718, Level: 10 Points: 718, Level: 10 Points: 718, Level: 10
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Many thanks.

Neal

A Northern Soul
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Unzip Zip Files using the Extraction Wizard southernsun VB How-To 0 December 6th, 2007 05:03 AM
Element extraction Neal XML 3 March 21st, 2007 04:53 AM
XSLT subtree extraction dextermagnific XSLT 5 June 30th, 2006 05:00 AM
regular expression extraction paragraph radhakrishnan1976 General .NET 0 April 7th, 2006 04:35 AM
Ch. 6 - Term Extraction Example ddouglas BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 March 20th, 2006 05:11 AM



All times are GMT -4. The time now is 03:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.