OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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