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 May 12th, 2007, 12:19 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Returning elements.

Hi,

I need to return 'ReferenceType' and 'AssignedBy in the following XML code.

[code<DeliveryLine LineNumber="1">
    <LineReference ReferenceType="Order Number" AssignedBy="Supplier">0007544778/01</LineReference>
[/code]

I have checked for the exact occurence using the following XSLT:

Code:
<xsl:for-each select="../DeliveryLine[@LineNumber]">
    <DeliveryLine LineNumber="{position()}">
        <xsl:for-each select="./*">
            <xsl:if test="name()='LineReference'">



Any ideas please?

Thanks in advance,



Neal

A Northern Soul
__________________
Neal

A Northern Soul
 
Old May 12th, 2007, 12:36 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Assuming that LineReference elements are children of DeliveryLine
Code:
<xsl:for-each select="../DeliveryLine[@LineNumber]">
    <DeliveryLine LineNumber="{position()}">
      <xsl:for-each select="LineReference>
        <xsl:value-of select="@ReferenceType"/>
        <xsl:value-of select="@AssignedBy"/>
or
Code:
<xsl:for-each select="../DeliveryLine[@LineNumber]">
    <DeliveryLine LineNumber="{position()}">
      <xsl:for-each select="*">
        <xsl:if test="self::LineReference">
          <xsl:value-of select="@ReferenceType"/>
          <xsl:value-of select="@AssignedBy"/>
        </xsl:if>
or, using templates
Code:
<xsl:for-each select="../DeliveryLine[@LineNumber]">
    <DeliveryLine LineNumber="{position()}">
      <xsl:apply-templates select="LineReference/>
</xsl:for-each>

<xsl:template match="LineReference">
        <xsl:value-of select="@ReferenceType"/>
        <xsl:value-of select="@AssignedBy"/>
</xsl:template>
--

Joe (Microsoft MVP - XML)
 
Old May 13th, 2007, 04:38 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

]<xsl:for-each select="../DeliveryLine[@LineNumber]">

Here the context node is a DeliveryLine

    <DeliveryLine LineNumber="{position()}">
        <xsl:for-each select="./*">

./* can be rewritten *, and selects the children of the context node. In your example the only child is a LineReference.

            <xsl:if test="name()='LineReference'">[/code]

If you're processing different child elements using different logic, then you ought to be using template rules, which are custom-designed for this purpose. Replace <xsl:for-each select="*"/> by <xsl:apply-templates/> and write a template rule for each possible kind of child element.

In the template rule for LineReference, you can get the values of the two attributes using the expressions

<xsl:value-of select="@ReferenceType"/>
<xsl:value-of select="@AssignedBy"/>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning Nothing from a constructor Imar Pro VB.NET 2002/2003 8 June 29th, 2012 02:00 PM
Returning a value Neal XSLT 6 October 13th, 2006 11:41 AM
Returning an Object taipeiben Visual C++ 2005 0 February 17th, 2006 07:24 PM
Function not returning value civa Access 5 January 17th, 2006 03:44 AM
Function not returning anything... goatboy Beginning PHP 2 December 1st, 2003 12:34 PM





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