XML , XSLT transformation of big text

I have XML with below structure

<ABC>
  <CDE>
     <FGH>
           <IJK>ABCDEXYZ22222222222222222222222333333333333333</IJK></FGH></CDE></ABC>

My requirement is is using XSL if <IJK> TEXT IS bigger than 10 characters then in xsl instead of displaying all in street1 should push to street2 beyond 5 CHARACTERS(ABCDE)

I MEAN like below
street1:ABCDE
Streer2:XYZ22222222222222222222222333333333333333

How to do using xml and xslt and then test it. Please advise
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
<xsl:if test="string-length(/ABC/CDE/FGH/IJK)  > 10">
  <street1><xsl:value-of select="substring(/ABC/CDE/FGH/IJK,1,5)"/></street1>
  <street2><xsl:value-of select="substring(/ABC/CDE/FGH/IJK,6)"/></street2>
</xsl:if>
gudii9Author Commented:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<showRoom id="someId">
    <name>Bikes Showroom</name>
    <bikeList>
        <bike vin="25631248">
            <color>black</color>
            <engineCapacity>250</engineCapacity>
        </bike>
        <bike vin="45896253">
            <color>red</color>
            <engineCapacity>200</engineCapacity>
        </bike>
        <bike vin="56982351">
            <color>yellow</color>
            <engineCapacity>22524987131451111</engineCapacity>
        </bike>
    </bikeList>
</showRoom>

Open in new window


if my xml is like above for example
string1=22524
string2=987131451111
how would i achieve in xslt?
please advise
gudii9Author Commented:
i get error like
Element type "xsl:if" must be followed by either attribute specifications, ">" or "/>".

when i write like
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:if test="string-length(/showRoom/bikeLis/bike[vin= '56982351'])>10")/>
  <street1><xsl:value-of select="substring(/showRoom/bikeLis/bike,1,5)"/></street1>
  <street2><xsl:value-of select="substring(/showRoom/bikeLis/bike,6)"/></street2>
</xsl:if>
</xsl:stylesheet>

Open in new window


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<showRoom id="someId">
    <name>Bikes Showroom</name>
    <bikeList>
        <bike vin="25631248">
            <color>black</color>
            <engineCapacity>250</engineCapacity>
        </bike>
        <bike vin="45896253">
            <color>red</color>
            <engineCapacity>200</engineCapacity>
        </bike>
        <bike vin="56982351">
            <color>yellow</color>
            <engineCapacity>22524987131451111</engineCapacity>
        </bike>
    </bikeList>
</showRoom>

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

gurpsbassiCommented:
<xsl:if test="string-length(/showRoom/bikeLis/bike[vin= '56982351'])>10")/>

You have closed your tag too early. Get rid of the / at the end
gurpsbassiCommented:
Also why are you doing:
string-length(/showRoom/bikeLis/bike[vin= '56982351'])

This will give the length of the bike node. This is not a TEXT node. I am assuming you want
string-length(/showRoom/bikeLis/bike[vin= '56982351']/engineCapacity)


Also you have spelt bikeList wrong
gudii9Author Commented:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:if test="string-length(/showRoom/bikeLis/bike[vin= '56982351']/engineCapacity)>10")>
  <street1><xsl:value-of select="substring(/showRoom/bikeLis/bike,1,5)"/></street1>
  <street2><xsl:value-of select="substring(/showRoom/bikeLis/bike,6)"/></street2>
</xsl:if>
</xsl:stylesheet>

Open in new window


i am getting error

[Fatal Error] NewXSL.xsl:4:88: Element type "xsl:if" must be followed by either attribute specifications, ">" or "/>".
gudii9Author Commented:
how to fix this error. Can you please post the working code of above XSL
Robert SchuttSoftware EngineerCommented:
There is still an error at the end of line 4. There is an extra closing parenthesis between the end of the select attribute's value and the right angle signifying the end of the opening xsl:if tag: ")>

Also, be careful with spelling errors: bikeLis doesn't exist, obviously should be bikeList.

Then, a more general issue I guess, maybe you were just showing a fragment of the xsl but you will need some more code in there to get it to process the data. Assuming you want to loop through all the bikes and decide what to output depending on the length of the engineCapacity you might need something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/showRoom|/showRoom/bikeList">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="/showRoom/name">
  <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="/showRoom/bikeList/bike">
  <xsl:element name="bike">
    <xsl:attribute name="vin"><xsl:value-of select="@vin"/></xsl:attribute>
    <xsl:copy-of select="color"/>
    <xsl:choose>
      <xsl:when test="string-length(engineCapacity)>10">
        <street1><xsl:value-of select="substring(engineCapacity,1,5)"/></street1>
        <street2><xsl:value-of select="substring(engineCapacity,6)"/></street2>
      </xsl:when>
      <xsl:otherwise>
        <street1><xsl:value-of select="engineCapacity"/></street1>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:element>
</xsl:template>

</xsl:stylesheet>

Open in new window

output:
<?xml version="1.0" encoding="utf-8"?>
<showRoom>
  <name>Bikes Showroom</name>
  <bikeList>
    <bike vin="25631248">
      <color>black</color>
      <street1>250</street1>
    </bike>
    <bike vin="45896253">
      <color>red</color>
      <street1>200</street1>
    </bike>
    <bike vin="56982351">
      <color>yellow</color>
      <street1>22524</street1>
      <street2>987131451111</street2>
    </bike>
  </bikeList>
</showRoom>

Open in new window

gudii9Author Commented:
when i ran above xsl with xml i have got transformed empy xml file as attached. please advise
testXSL.png
Robert SchuttSoftware EngineerCommented:
well I can't really see what's going on in your environment from that screenshot but when I input your source xml with the xsl I posted in an online xsl tester for example http://xslttest.appspot.com/ then I get some output that seems to be what you needed:
xslt test

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.