1

Hello I have xml input

<?xml version="1.0" encoding="UTF-8"?>
<?Xpress productline="smartdoc"?>
    <section xmlns="http://w3.com/content/3.0" id="_f6ded403-f94f-4123-a2f2-5ae75e482d88" type="document">
        <title>UI/UX Elements</title>
        <section id="_192a87c8-6754-472e-9ab3-4d760c071004" type="section">

            <body>
                <region id="_6cf44f92-1de1-4603-a4a7-1ac2e2020508" type="callout">
                    <p>
                        <t><b>Key Point</b>:&#160;There are four basic types of curation that L&amp;D departments should leverage:&#160;traditional, self, machine, and social.</t>
                    </p>
                </region>
                <p>
                    <t>&#160;</t>
                </p>
                <region id="_b0ec8f84-65ea-4590-a1da-ee6f79a2af67" type="callout">
                    <p>
                        <t><b>ANALYSIS</b>: There are four basic types of curation that L&amp;D departments should leverage: traditional, self, machine, and social.</t>
                    </p>
                </region>
                <p>
                    <t>&#160;</t>
                </p>
                <p>
                    <t>&#160;</t>
                </p>
                <region id="_72ced280-a2fe-499b-af54-c32c1414f7e1" type="callout">
                    <p>
                        <t><b>PREDICTION</b>: There are four basic types of curation that L&amp;D departments should leverage: traditional, self, machine, and social. There are four basic types of curation that L&amp;D departments should leverage: traditional, self, machine, and social.</t>
                    </p>
                </region>
            </body>
        </section>
    </section>

And the following XSLT

<xsl:template match="region">
    <xsl:element name="div">
        <xsl:attribute name="id" select="@id"/>
        <xsl:choose>
            <xsl:when test="@type = 'box' and (//region/region/region[@type='box'])">
                <xsl:attribute name="class" select="'key-takeaways no-accordian'"/>
                <xsl:apply-templates/>
            </xsl:when>
            <xsl:when test="(./p/t/b[starts-with(lower-case(.), 'prediction')]">
                <xsl:attribute name="class" select="'prediction'"/>
                <xsl:apply-templates/>
            </xsl:when>
            <!-- <xsl:when test="(//region[@type='callout'])/p/t/b[starts-with(lower-case(.), 'prediction')]">
                <xsl:attribute name="class" select="'prediction'"/>
                <xsl:apply-templates/>
            </xsl:when> -->
            <xsl:when test="(//region[@type='callout'])/p/t/b[starts-with(lower-case(.), 'key')]">
                <xsl:attribute name="class" select="'key-point'"/>
                <xsl:apply-templates/>
            </xsl:when>
            <xsl:when test="@type = 'box'">
                <xsl:attribute name="class" select="'box-region'"/>
                <xsl:apply-templates/>
            </xsl:when>
            <xsl:when test="@type = 'callout'">
                <xsl:attribute name="class" select="'callout-region row'"/>
                <xsl:attribute name="style" select="'width : 100%'"/>
                <xsl:apply-templates/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:attribute name="class" select="'default-region'"/>
                <xsl:apply-templates/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:element>
</xsl:template>

The structure of the document is going to always be the same and I have to apply specific class name depending on the text inside the /region/p/t/b node i.e if that value is Key Point then the class name will be key-point if the value is Analysis the class name is analysis and so on.

The xslt that I currently have applies the prediction class to all the elements (i think) for some reason it is not honoring the start-with condition. I have to use xsl choose as we will be adding more elements in future and I feel that will be the best way to check for addition elements in future.

Thank you for your time.

Edit1: Final HTML Output

<div id="_6cf44f92-1de1-4603-a4a7-1ac2e2020508" class="key-point">
    <p>
        <b>KEY&nbsp;POIINT</b>:&nbsp;There are four basic types of curation that L&amp;D departments should leverage:&nbsp;traditional, self, machine, and social.
    </p>
</div>
<p>
    &nbsp;
</p>
<div id="_b0ec8f84-65ea-4590-a1da-ee6f79a2af67" class="key-point">
    <p>
        <b>ANALYSIS</b>: There are four basic types of curation that L&amp;D departments should leverage: traditional, self, machine, and social.
    </p>
</div>
<p>
    &nbsp;
</p>
<p>
    &nbsp;
</p>
<div id="_72ced280-a2fe-499b-af54-c32c1414f7e1" class="key-point">
    <p>
        <b>PREDICTION</b>: There are four basic types of curation that L&amp;D departments should leverage: traditional, self, machine, and social. There are four basic types of curation that L&amp;D departments should leverage: traditional, self, machine, and social.
    </p>
</div>
Parik Tiwari
  • 1,525
  • 1
  • 12
  • 19
  • That single template does not even allow us whether you match the input elements as they are in a namespace and you do not show us any context for the stylesheet. And in some places of your `xsl:when test`s you use a relative path like `./p/t/b`, in others an absolute path like `//region`, is that intentional? – Martin Honnen Aug 10 '17 at 20:14
  • I am new to xslt, is the namespace code necessary to get the desired output? yes I am trying different things (relative/absolute path) to make the string comparison to pass – Parik Tiwari Aug 10 '17 at 20:22
  • Search for "XSLT default namespace" to get about 1000 answers to this problem. – Michael Kay Aug 11 '17 at 23:21

0 Answers0