0

I'm trying to transform the following HTML code, but having problems with getting the values needed and using the substring function for the XSLT. This is part of the HTML code that I'm trying to transform:

<th scope="row">2005DEC</th>
<td>2,757</td>

to the following XML code:

<?xml version="1.0"?>
<Original>
    <Entry>
        <Year>2005</Year>
        <Month>DEC</Month>
        <Age>
            <Group>
                <value>90</value>
            </Group>
        </Age>
    </Entry>
</Original>

I'm trying to run the XSLT query, but it keeps getting an error. My XSLT is:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
    <Original>
        <xsl:for-each select="@scope=row">
            <Entry>
                <Year>
                    <xsl:value-of select="substring(@scope=row, 1, 4)"/>
                </Year>
                <Month>
                    <xsl:value-of select="substring(@scope=row, 5, 3)"/>
                </Month>
                <Age>

                <Group>

                    <value>
                        <xsl:value-of select="td[1]"/>
                    </value>
                </Group>

                </Age>
            </Entry>
        </xsl:for-each>
    </Original>
    </xsl:template>


</xsl:stylesheet>

The error is:

Ivans-MacBook-Pro:xslt-test ivanteong$ java -jar saxon9he.jar table823.html table823.xslt > out.xml
Error at xsl:value-of on line 13 column 73 of table823.xslt:
  XPTY0004: Required item type of first argument of substring() is xs:string; supplied value
  has item type xs:boolean
Error at xsl:value-of on line 16 column 73 of table823.xslt:
  XPTY0004: Required item type of first argument of substring() is xs:string; supplied value
  has item type xs:boolean
Failed to compile stylesheet. 2 errors detected.
1

2 Answers 2

2

Well, with the expression

<xsl:value-of select="substring(@scope=row, 5, 3)"/>

it's fairly obvious, I hope, why you are getting the error message

Required item type of first argument of substring() is xs:string; supplied value has item type xs:boolean

We don't know what your complete input tree is, but try this for starters:

            <Group>

                <value>
                    <xsl:value-of select="following-sibling::td[1]"/>
                </value>
            </Group>

            </Age>
        </Entry>
    </xsl:for-each>
</Original>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

1

It's difficult to advise without knowing what the context is. I guess you wanted to do:

<xsl:value-of select="substring(th[@scope='row'], 1, 4)"/>

This will work if the current context is the parent node of the th element.


Note that:

<xsl:for-each select="@scope=row">

is invalid syntax, too - but I don't know how to fix it without seeing how your XML is structured.

6 Comments

I'm trying to get the values between the opening and closing tags, and slicing them using the substring function. But I'm having trouble trying to do that since it is an attribute.
@iteong Please post a minimal but complete XML too.
Just did... is that ok?
I don't see that you have. I meant your XML input.
The input is HTML. Supposed to transform HTML to XML using XSLT.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.