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 July 15th, 2007, 09:36 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding lines after generate xsl file

hello

this is my xml file
<entity-single><t id="501">ServiceID</t><t id="511">HandlerType</t><t id="521">ClassName</t><t id="531">CommandLine</t><t id="551">ServerProduct</t><t id="561">ExitCode</t><t id="571">RealCommunication</t></entity-single>

currently I am generating the file with copy-template and it copy all this part. (this is the part that copy)
<xsl:otherwise>
   <xsl:copy>
      <xsl:apply-templates />
   </xsl:copy>
</xsl:otherwise>

I would like to know, if I can after copying it, to add to each 't' attribute a string (hello for example) so the new out put will be
<entity-single><t id="501">helloServiceID</t><t id="511">helloHandlerType</t><t id="521">helloClassName</t><t id="531">helloCommandLine</t><t id="551">helloServerProduct</t><t id="561">helloExitCode</t><t id="571">helloRealCommunication</t></entity-single>

can be either by use of a new function that just copy the string or maybe an xsl command that can add only for the 't' element the string.

thanks

 
Old July 15th, 2007, 02:04 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Add the template rule

<xsl:template match="t/text()">
  <xsl:text>Hello</xsl:text>
  <xsl:value-of select="."/>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 16th, 2007, 01:01 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it may sound stupid, but when I call the template, it add in the end each entity and its prefix (this is the out put
<iNaN>Service ID</iNaN>
<iNaN>Handler Type</iNaN>
<iNaN>Class Name</iNaN>
<iNaN>Command Line</iNaN>
<iNaN>Server Product</iNaN>
<iNaN>Exit Code</iNaN>
<iNaN>Real Communication</iNaN>
<iNaN>Instance</iNaN>
<iNaN>Server</iNaN>
<iNaN>Client Product</iNaN>
<iNaN>Client Host</iNaN>
</entity-single>
<entity>!~graphTitlePrefix!~Service IDs!~graphTitlePrefix!~Handler Types!~graphTitlePrefix!~Class Names!~graphTitlePrefix!~Command Lines!~graphTitlePrefix!~Server Products!~graphTitlePrefix!~Exit Codes!~graphTitlePrefix!~Real Communications!~graphTitlePrefix!~Instances!~graph TitlePrefix!~Servers!~graphTitlePrefix!~Client Products!~graphTitlePrefix!~Client Hosts

I believe I am not calling the template corect or that I am missing something.
in my xsl I called the template this way
...
    <xsl:otherwise>
       <xsl:copy>
        <xsl:apply-templates select = "t/text()" />
           <xsl:apply-templates />
       </xsl:copy>
    </xsl:otherwise>
</xsl:template>


<xsl:template match="t/text()">
  <xsl:text>!~graphTitlePrefix!~</xsl:text>
  <xsl:value-of select="."/>
</xsl:template>

am I not calling the template correct?

 
Old July 16th, 2007, 03:20 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's displaying twice because you're applying templates twice

  <xsl:apply-templates select = "t/text()" />
  <xsl:apply-templates />

You don't need to add an apply-templates call to your existing code provided that your existing code is already doing a recursive descent of the tree (all the way down to the text nodes) using apply-templates without parameters. You haven't shown your whole code so I can't be sure this is the case, but it looks like it from the evidence of the output.


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
Using XSL to generate single pdf doc bhavanimachani XML 2 March 24th, 2008 11:57 PM
Need to Count number of lines in a file lawsoncobol Access VBA 2 July 19th, 2007 04:28 AM
how to count lines in word file arshad mahmood VB How-To 2 June 7th, 2006 09:40 PM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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