xsl: build a dynamic tag based on parsing string that I get from XML file using xsl

I  need to be able to build a dynamic tag based on parsing string that I get from XML file using xsl. For  example,
1.      Parse a pipe delimited string value1|type|value2
2.       If type = XYZ1
then  < ABC  name1=value2 name2=type>
                            value1
           </ABC>
3.      If type = XYZ2
then  < ABC  name1=value2 name2=type
                  value1
 </ABC>

jgordinAsked:
Who is Participating?
 
Geert BormansConnect With a Mentor Information ArchitectCommented:
make it an apply-templates
<xsl:apply-templates select="xyz5"/>

the node will then be passed to the template for xyz5

then you can put the above code in the template for "xyz5", like this
 
<xsl:template match="xyz5">
        <ABC name1="{substring-after(substring-after(., '|'), '|')}" name2="{substring-before(substring-after(., '|'), '|')}">
            <xsl:value-of select="substring-before(., '|')" />
        </ABC>
    </xsl:template>
0
 
jgordinAuthor Commented:
correction:
2.   If type = XYZ1
then  < ABC  name1="value2" name2="type">
                            value1
           </ABC>
3.      If type = XYZ2
then  < ABC  name1="value2" name2="type"
                  value1
0
 
Geert BormansInformation ArchitectCommented:
I see no difference between the first condition and the second

Can you use XSLT2.0?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
jgordinAuthor Commented:
this is what i use:

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:str="http://exslt.org/strings" exclude-result-prefixes ="str">

0
 
Geert BormansInformation ArchitectCommented:
Assuming that you don't need the test and there are only two '|'
(I have stuffed the string in  <text> element)

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="text">
        <ABC name1="{substring-after(substring-after(., '|'), '|')}" name2="{substring-before(substring-after(., '|'), '|')}">
            <xsl:value-of select="substring-before(., '|')" />
        </ABC>
    </xsl:template>
</xsl:stylesheet>
0
 
jgordinAuthor Commented:
the only difference between first and second conditions is type.
0
 
jgordinAuthor Commented:
Gertone:
let me test your solution.

thanks.
0
 
jgordinAuthor Commented:
how do i pass a string that i need to match?

that is, i do xsl:value-of select="xyz5", where xyz5 is a tag in the XML file that i parse. the select statement returns string value1|type|value2. thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.