Machine Gun
Machine Gun

Reputation: 65

xslt parameter error in a href link

<xsl:value-of select="jobpageno"/>

above code do not have error, it can be success run and display page.

however, below code got error, after remove &PageNo={@jobpageno}, then success to display.

<a href="http://www.hello.com/description.aspx?ID={@id}&PageNo={@jobpageno}" target="_top">

what's wrong with this link containing this parameter

An error occurred while parsing EntityName. Line 58, position 103

it should show hello.com/description.aspx?ID=753561&PageNo=1

<a href="http://www.hello.com/description.aspx?ID={@id}&PageNo={jobpageno}" target="_top">

also got error

pageno is just one of element

<jobresults jobcount='1'>
<header1><![CDATA[ IT Jobs]]></header1>
<header2><![CDATA[1 Results for ' IT' in Asia]]></header2>
<entity id='753561' index='1'>
<position><![CDATA[Ecommerce Project Manager]]></position>
<jobCountry><![CDATA[Singapore]]></jobCountry>
<posteddate><![CDATA[January 2013]]></posteddate>
<JobDefaultRole><![CDATA[Contract]]></JobDefaultRole>
<jobTypeDesc><![CDATA[Jobs In IT]]></jobTypeDesc>
<jobDetails><![CDATA[ Ecommerce Project Manager Client Description Our  ...]]></jobDetails>
<jobpageno><![CDATA[1]]></jobpageno>
</entity>
</jobresults>


 <xsl:for-each select="jobresults/entity">
              <xsl:choose>
                <xsl:when test="position() mod 2 = 0">
                  <tr class="odd">
                    <td>
                      <a href="http://www.hello.com/job-description.aspx?jobID={@id}&jobPageNo={@jobpageno}" target="_top">
                        <xsl:value-of select="position"/>
                        <xsl:value-of select="jobpageno"/>
                      </a>
                    </td>

Upvotes: 0

Views: 357

Answers (2)

Ian Roberts
Ian Roberts

Reputation: 122364

An XSLT file must be well formed XML so you need to escape the &:

<a href="http://www.hello.com/description.aspx?ID={@id}&amp;PageNo={jobpageno}" target="_top">

The actual error message you're seeing is because the parser sees &PageNo as the start of an entity reference but then can't find the terminating semicolon.

Upvotes: 2

Tim C
Tim C

Reputation: 70598

It may be just a typo in your question, but in your first XSLT sample you use pageno, which means it is an element, but in your second XSLT sample you do @pageno which means it is looking for an attribute.

Perhaps you mean to do this:

 <a href="http://www.hello.com/description.aspx?ID={@id}&PageNo={pageno}" target="_top">

Note, there is nothing actually wrong with the syntax of your XSLT sample. If you reference an attribute that does not exist, it will just be output as a blank, and all will happen is the href attribute will not be complete as you expect.

EDIT: From looking at your amended question, there is neither an attribute or an element called pageno. Perhaps you mean to use jobpageno?

 <a href="http://www.hello.com/description.aspx?ID={@id}&PageNo={jobpageno}" target="_top">

Upvotes: 1

Related Questions