Note that there are some explanatory texts on larger screens.

plurals
  1. PORename a batch of values with xslt
    primarykey
    data
    text
    <p>We have a program that uses xml to save configurations of our program. Someone decided to rename a couple of values in our database and these renames should now also be backwards compatible in the configurations of our customers.</p> <p>An example of a configuration</p> <pre><code>&lt;configuration&gt; &lt;fruitToEat&gt;yellow_curved_thing&lt;/fruitToEat&gt; &lt;!-- should now become banana --&gt; &lt;/configuration&gt; </code></pre> <p>A simple match would be (not tested, just an example):</p> <pre><code>&lt;xsl:template&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match"/configuration/fruitToEat/text()"&gt; &lt;xsl:text&gt;banana&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;/xsl:template&gt; </code></pre> <p>But this is just one example and I want to do this 150 times. </p> <blockquote> <p><em>Is it possible to make an xsl that reads a simple text file or ini file that tells me how the 150 matches should look alike?</em></p> </blockquote> <pre><code>&lt;xsl:template&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;!-- recreate this template 150 times from an ini file or something --&gt; &lt;xsl:template match"/configuration/fruitToEat/text()[.='yellow_curved_thing']"&gt; &lt;xsl:text&gt;banana&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;/xsl:template&gt; </code></pre> <p>An example of my mapping file could be simply:</p> <pre><code>yellow_curved_thing = banana round_thing = tomato round_dotted = strawberry </code></pre> <p>And I would simply want a small xslt that tells me:</p> <pre><code>&lt;xsl:template&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;!-- recreate this template 150 times from an ini file or something --&gt; &lt;xsl:template match"/configuration/fruitToEat/text()[.=$fileRow0]"&gt; &lt;xsl:text&gt;$fileRow1&lt;/xsl:text&gt; &lt;/xsl:template&gt; &lt;/xsl:template&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload