0

I am trying to convert placeholders strings that look like:

<param>Hello {0}</param>

to output

Hello <%- {0} ->
<ini>
    <params>
        <param name=hello">Hello {0}</param>
    </params>
</ini>

Any suggestions?

slik
  • 5,001
  • 6
  • 34
  • 40

2 Answers2

0

This should do it, if there is only one token, otherwise it gets much tougher.

<xsl:template match="param">
  <xsl:value-of select="substring-before(.,'{')"/>
  <xsl:text>&lt;%- </xsl:text>
  <xsl:value-of select="substring-after(substring-before(.,'}'),'{')"/>
  <xsl:text> -&gt;</xsl:text>
  <xsl:value-of select="substring-after(.,'}')"/>
</xsl:template>
0

I forgot to post my solution, in case anyone runs into this. I ended up changing the definition of my placeholders to be {%token%}.

<xsl:template name="tokenReplacer">
    <xsl:param name="strToConvert" />
    <xsl:variable name="after" select="substring-after($strToConvert,'{%')"/>
    <xsl:choose>
        <xsl:when test="contains($after,'%}')">
            <xsl:value-of select="substring-before($strToConvert, '{%')" />
            <xsl:text>&lt;%=</xsl:text>
            <xsl:value-of select="substring-before($after,'%}')"/>
            <xsl:text>%&gt;</xsl:text>
            <xsl:call-template name="tokenReplacer">
                <xsl:with-param name="strToConvert" select="substring-after($after,'%}')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$strToConvert"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
slik
  • 5,001
  • 6
  • 34
  • 40