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 December 19th, 2003, 11:50 AM
Registered User
 
Join Date: Dec 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sk36
Default Using parameters without match="/ABC/..

Hi all,:)

I am passing parameter values to an XSL file, and transforming an xml file successfully using VB.net. This transformation keeps xml as xml (Copy), and just inserts new tags having the parameter values. In the xsl, I have these lines:
<xsl:param name="param1">dummy</xsl:param>
  <xsl:template match="/ABC/zzzz1">
    <Annotations>
    <xsl:value-of select="$param1"/>
    </Annotations>
  </xsl:template>

The XML has to have <zzzz1></zzzz1> tags under the <ABC> tag for the template to locate the place where <Annotations> tags with param1 value can be inserted.

Is it possible to insert the <Annotations> tags and param1 value at the top or bottom of the xml file without the <zzzz1> tags being there?

TIA,
Sudhir
 
Old December 19th, 2003, 12:22 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Yes. Just have the annotations under the document element in an element called 'Annotations' and match on "/*/Annotations". As your not using content from abc/zzzz1 I can't see what's happening. Why not show a small examle of what you have now with an indication of what you need?

Joe (MVP - xml)
 
Old December 19th, 2003, 01:02 PM
Registered User
 
Join Date: Dec 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sk36
Default

Joe,

My xml file has following structure
<ABC>
 <zzzz1>dummy</zzzz1>
....other tags go here....
</ABC>

The tag <zzzz1>dummy</zzzz1> is only a place holder, and is referenced in the xsl by match="/ABC/zzzz1".

I want to do without the <zzzz1>dummy</zzzz1> tag in the xml. I don't care where the xsl places the new <Anottations> tags with parameter value. Can it be done?

Thanks a lot,
Sudhir
 
Old December 19th, 2003, 01:09 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well ditch the zzzz1 and in the xslt under the root match add your param1 value:
Code:
<xsl:template match="/">
  <Annotations> 
    <xsl:value-of select="$param1"/> 
  </Annotations>
</xsl:template>
You may find it convenient to use a different template. If you still can't get it to work as needed post the xml and xsl in full along with the desired output.

Joe (MVP - xml)
 
Old December 19th, 2003, 01:40 PM
Registered User
 
Join Date: Dec 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sk36
Default

That doesn't work.

The complete xsl is:
-------------------------------------------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="param1">1</xsl:param>

  <xsl:template match="/">
    <Annotations>
    <xsl:value-of select="$param1"/>
    </Annotations>
  </xsl:template>


  <xsl:template match="node()|@*">

    <xsl:copy>

      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
------------------------------------
and the xml is:
------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<!ABC SYSTEMS "ABC.dtd"[]>
<?Pub Inc?>
<ABC>
<zzzz1></zzzz1>
  <State-use>
    <State-para>
    </State-para>
  </State-use>
....hundreds of other tags....

</ABC>
------------------------------------
 
Old December 19th, 2003, 02:03 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Now I understand...
If your initial xml is (I've removed the dtd and pi and added some stuff to prove that all attributes etc. get copied:
Code:
<ABC>  
    <State-use item="1">
      <State-para>Para 1
      </State-para>
    </State-use>
  <State-use item="2">
      <State-para>para 2
      </State-para>
  </State-use>
  <State-use item="3">
      <State-para>Para 3
      </State-para>
  </State-use>
</ABC>
then override the default match and copy by having a more specific match:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="param1">Added as parameter</xsl:param> 

  <xsl:template match="ABC">    
    <xsl:copy>
      <Annotations> 
        <xsl:value-of select="$param1"/> 
      </Annotations>

      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>


  <xsl:template match="node()|@*">

    <xsl:copy>

      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
Joe (MVP - xml)
 
Old December 19th, 2003, 02:29 PM
Registered User
 
Join Date: Dec 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sk36
Default

That works great!
Thanks a million.
Sudhir






Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Match Mitali XSLT 7 July 24th, 2008 03:39 AM
typing abc.com opens http://abc.com and not http:/ nrlahoti ASP.NET 2.0 Professional 1 February 6th, 2008 01:43 PM
Update ABC.asp with a new date shown automatically cJeffreywang ASP.NET 2.0 Professional 1 July 18th, 2007 11:29 AM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
Match by attribute. ole_v2 XSLT 6 November 11th, 2006 10:24 AM





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