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 March 21st, 2007, 05:38 AM
Friend of Wrox
 
Join Date: Jan 2006
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
 
Old March 21st, 2007, 06:12 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old March 21st, 2007, 06:27 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Many thanks.

Neal

A Northern Soul





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





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