XSLT problem. Can I please have a little help here to create a hyperlink.

M

mark4asp

I want to write a xslt template to create a xhtml 1.0 (transitional)
file which will be sent in as email.

Here is a typical xml data file:

<BatchEmail>
<Domain>www.myDomain.com</Domain>
<Destination>
<Salutation>Hi Mark</Salutation>
<UniqueID>4120</UniqueID>
<Folder>Lite</Folder>
</Destination>
<Reports>
<Report ID="3434">
<Headline>'Triffids' Are Invading!</Headline>
<Preface>Giant mobile plant-like creatures have descending on
Cheltenham and are attacking all animals in sight. Scientists have
named these mysterious creatures 'Triffids'.</Preface>
</Report>
<Report ID="3435">
<Headline>Martian Ambassador Causes Diplomatic Incident</Headline>
<Preface>The Martian ambassador has caused a diplomatic incident
after it accidently eat the Big Apple. On immediately regurgitating New
York City the Ambassador was heard to mutter 'didn't taste anything
like an apple'</Preface>
</Report>
</Reports>
</BatchEmail>


This is what I need the xlst to create from that:

<p>Hi Mark,</p>
<h4>'Triffids' Are Invading!</h4>
<p>Giant mobile plant-like creatures have descending on Cheltenham and
are attacking all animals in sight. Scientists have named these
mysterious creatures 'Triffids'.</p>
<p>Read the full report here:<br /><a target="_blank"
href="http://www.myDomain.com/Lite/ViewReport.aspx?ReportID=3434">http:/
/www.myDomain.com/Lite/ViewReport.aspx?ReportID=3434</a></p>
<h4>Martian Ambassador Causes Diplomatic Incident</h4>
<p>The Martian ambassador has caused a diplomatic incident after it
accidently eat the Big Apple. On immediately regurgitating New York
City the Ambassador was heard to mutter 'didn't taste anything like an
apple'</p>
<p>Read the full report here:<br /><a target="_blank"
href="http://www.myDomain.com/Lite/ViewReport.aspx?ReportID=3435">http:/
/www.myDomain.com/Lite/ViewReport.aspx?ReportID=3435</a></p>


When the xml file has a Folder value of Full (in place of Lite). I'd
like a slightly different xhtml (i.e. with an extra line):

<p>Hi Mark,</p>
<h4>'Triffids' Are Invading!</h4>
<p>Giant mobile plant-like creatures have descending on Cheltenham and
are attacking all animals in sight. Scientists have named these
mysterious creatures 'Triffids'.</p>
<p>Read the full report here:<br /><a target="_blank"
href="http://www.myDomain.com/Full/ViewReport.aspx?ReportID=3434">http:/
/www.myDomain.com/Full/ViewReport.aspx?ReportID=3434</a></p>
<h4>Martian Ambassador Causes Diplomatic Incident</h4>
<p>The Martian ambassador has caused a diplomatic incident after it
accidently eat the Big Apple. On immediately regurgitating New York
City the Ambassador was heard to mutter 'didn't taste anything like an
apple'</p>
<p>Read the full report here:<br /><a target="_blank"
href="http://www.myDomain.com/Full/ViewReport.aspx?ReportID=3435">http:/
/www.myDomain.com/Full/ViewReport.aspx?ReportID=3435</a></p>
<p>You can do a full search of our database at the search page: <a
target="_blank"
href="http://www.myDomain.com/Search/Search.aspx">http://www.myDomain.co
m/Search/Search.aspx</a></p>


I'm having some trouble creating the the url in the hyperlink. For
instance my editor shows it as so (in the .net 2.0 framework, Browser
object windown):

http://{$domain}/{$folder}/ViewReport.aspx?ReportID=1001

Navigating from there takes me to this page:

http://{$domain}/{$folder}/ViewReport.aspx?ReportID=1001

That comes from the following xslt:

<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:v
alue-of select="@ID"/></span>

That xslt snippet above is itself inside a loop. So the relevant part
is:

<xsl:variable name="domain" select="BatchEmail/Domain"/>
<xsl:variable name="folder" select="BatchEmail/Destination/Folder"/>
<xsl:for-each select="BatchEmail/Reports/Report">

blah blah ...

<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:v
alue-of select="@ID"/></span>

blah blah blah ...
<xsl:if test="$folder = 'Full'">
blah blah blah blah ...
</xsl:if>

blah blah blah blah blah ...

</xsl:for-each>


[the 1001 there is OK, it's just a place holder for the actual value
from the xml. The editor doesn't know anthing about an actual data file
at this stage as email posting is not yet running (as I haven't even
saved my xslt template yet.)

I having tested this program yet as I need to enter the relevant 'Lite'
users in the database, make sure the web service is propertly running
etc. and I'm not confident with that url above.
 
T

TOUDIdel

Uzytkownik "mark4asp said:
I want to write a xslt template to create a xhtml 1.0 (transitional) file
which will be sent in as email.


<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:v
alue-of select="@ID"/></span>


should be like that:


<a target="_blank"><xsl:attribute
name="href">http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://<xsl:value-of select="$domain"/>//<xsl:value-of
select="$folder"/>//ViewReport.aspx?ReportID=<xsl:v
alue-of select="@ID"/></span>
 
M

mark4asp

TOUDIdel said:
<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:v
al ue-of select="@ID"/></xsl:attribute>
<span
class="link2">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl
:v alue-of select="@ID"/></span>


should be like that:


<a target="_blank"><xsl:attribute
name="href">http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:val ue-of
select="@ID"/></xsl:attribute> <span
class="link2">http://<xsl:value-of select="$domain"/>//<xsl:value-of
select="$folder"/>//ViewReport.aspx?ReportID=<xsl:v alue-of
select="@ID"/></span>

So if I reduce it to the simplest form, is this it:

<a target="_blank" class="link2"><xsl:attribute
name="href">http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:value-of
select="@ID"/></xsl:attribute>
http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:value-of select="@ID"/>
</a>

I notice you have two / where I only have one (in the display part of
the hyperlink). Is your's a typo or is my hyperlink above wrong?
 
D

David Carlisle

I'm having some trouble creating the the url in the hyperlink. For
instance my editor shows it as so (in the .net 2.0 framework, Browser
object windown):
<a target="_blank"><xsl:attribute
name="href">http://{$domain}/{$folder}/ViewReport.aspx?ReportID=<xsl:val
ue-of select="@ID"/></xsl:attribute>


{} braces are just character data when used in element content. You have
to use xsl:value-of in that context (as you did for @ID)
so
<a target="_blank"><xsl:attribute
name="href">http://<xsl:value-of select="$domain"/>/<xsl:value-of
select="$folder"/>/ViewReport.aspx?ReportID=<xsl:value-of
select="@ID"/></xsl:attribute>

or more simply use attribute value templates:

<t target="_blank"
href="http://{$domain}/{$folder}/ViewReport.aspx?ReportID={@ID}">

David
 
T

TOUDIdel

U¿ytkownik "mark4asp said:
I notice you have two / where I only have one (in the display part of
the hyperlink). Is your's a typo or is my hyperlink above wrong?

what's the problem? there are many equivalent solutions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top