[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: To Buy, or to Build? That is the q...

  • From: Jeff Rafter <jeffrafter@e...>
  • To: "Wedinger, Keith" <Keith_Wedinger@s...>, xml-dev@l...
  • Date: Mon, 05 Mar 2001 14:07:45 -0800

Re: To Buy
Keith,

Hadn't seen an answer to this one yet so I thought I would embarass myself
and give it a whack.

[snip]

>and I want to go through my entire xml and find all the references of
#{Id}#, and then find the >Node with that id, and replace the references
with the name of the found node, so that for >example,  the third line would
become

[snip]

Well this obviously skips some of the important details about copying the
existing nodes and just handles the replacement of the text (which I assume
was the problem)-- and it is definitely not optimized for speed, and it
doesn't take many things into consideration, and...  That being said:

<root>
  <Node Id="2001" Name="Statement1">
    <Input>
       <Parameter Key="Line 1" Value="use #2002# here" />
    </Input>
  </Node>
  <Node Id="2002" Name="Statement2">
    <Input>
       <Parameter Key="Line 1" Value="a" />
    </Input>
  </Node>
</root>

================

<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <!--Set the output method -->
  <xsl:output method="text" encoding="UTF-8" indent="yes"/>

  <xsl:template match="/">
    <xsl:for-each select="//Parameter/@Value">
      <xsl:if test="contains(current(), '#')">
        <xsl:variable name="temp" select="substring-after(current(), '#')"/>
        <xsl:variable name="leading" select="substring-before(current(),
'#')"/>
        <xsl:variable name="trailing" select="substring-after($temp, '#')"/>
        <xsl:variable name="refId" select="substring-before($temp, '#')"/>
        <xsl:variable name="refValue" select="//Node[@Id=$refId]/@Name"/>
        <xsl:value-of select="concat($leading, ' ', $refValue, ' ',
$trailing)"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

I obviously changed a little in your sample instance and the output of this
stylesheet leaves much to the imagination (it is only the new Value
attribute text).  Also I will point you to the much better list [1] for
these questions and the FAQ [2] as I saw you said you recently purchased a
book and figure you will need it sooner or later (I know I have).

[1] http://www.mulberrytech.com/xsl/xsl-list/index.html
[2] http://www.dpawson.co.uk/xsl/xslfaq.html

Good Luck!
Jeff Rafter


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.