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 September 7th, 2006, 01:23 AM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Transform - need assistance

Hello,

I have tried a few unsuccessful attempts and am looking for help. I have the following:

XML:
Code:
<list>
  <item>
    <response>

      <header value1=""
              value2="">
        <error index="1" value3="" />
        <error index="2" value4="" />
        <error index="3" value5="" />

        <detail value6=""
                value7="">
          <error index="1" value8="" />
          <error index="2" value9="" />
          <error index="3" value0="" />
        </detail>
      </header>
    </response>
  </item>
</list>
XSLT:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:template match="/">
    <Response>
      <xsl:apply-templates select="//list/item/response/header" />
    </Response>
  </xsl:template>
  <xsl:template match="header">
    <Header>
      <xsl:attribute name="MyValue1">
        <xsl:value-of select="@value1" />
      </xsl:attribute>
      <xsl:attribute name="MyValue2">
        <xsl:value-of select="@value2" />
      </xsl:attribute>
    </Header>
  </xsl:template>
</xsl:stylesheet>
I am trying to get access to the Header errors, detail and detail errors. The header only occurs once, but the rest can all occur multiple times.

Any suggestions on the rest of the XSLT needed? I am new to XSLT so if I have not provided enough information, let me know.
 
Old September 7th, 2006, 01:58 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You don't say how you want to process the data when you find it, but the simplest approach is to do

<xsl:apply-templates/>

from within the match="header" template, and then write template rules for

<xsl:template match="header/error">

<xsl:template match="detail">

<xsl:template match="detail/error">

in each case calling xsl:apply-templates to process any children.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 7th, 2006, 12:38 PM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response Michael. With a little bit of trial and error, I was able to get what I need.





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Time transform blackest XSLT 10 April 1st, 2008 03:07 AM
XSLT: ONE template to transform all the elements Behl_Neha XSLT 8 December 15th, 2007 07:31 PM
transform in xslt kgoldvas XSLT 1 January 24th, 2006 07:14 AM
XSLT Assistance MarkHA XSLT 0 November 7th, 2005 12:08 AM
XSLT Transform scubaduba C# 0 November 30th, 2004 06:31 AM





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