You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Chris Gokey <cg...@gcmd.gsfc.nasa.gov> on 2000/08/24 03:27:29 UTC

can xalan hypertext link urls in xml tags?

Hi everyone,

Given an XML file like this:

<Book>
   <Title>Master Xalan the XSLT processor</Title>
   <Summary>
     Xalan is an XSLT processor for transforming XML documents into HTML, text, or other
     XML document types. Xalan-Java version 1.2.D01 represents a complete and robust
     reference implementation of the W3C Recommendations for XSL Transformations XSLT) 
     and the XML Path Language (XPath).  See http://xml.apache.org/xalan for more
     details.
   </Summary>
</Book>

Is there some mechanism in Xalan to hypertext link urls found inside the 
element tags?  In the above example, I'd like to present the XML file in
HTML with the 'http://xml.apache.org/xalan' hypertext linked.

Someone mentioned sometime back the possibility of using templates and
string functions, but it is not obvious to me how this can be done.
This would appear to be a common thing, some I'm hoping there is already
something built into Xalan.  Any suggestions, code, examples would be very
appreciated.

Chris

-- 
Christopher D. Gokey, Raytheon ITSS, NASA/GCMD
18 Martin Road, Shelburne Falls, MA  01370
Phone: Voice (413) 625-8129 / FAX 208-248-9055
cgokey@gcmd.nasa.gov / http://gcmd.nasa.gov

Re: can xalan hypertext link urls in xml tags?

Posted by Chris Gokey <cg...@gcmd.gsfc.nasa.gov>.
That did it!  Thanks.

Chris


Conny Krappatsch wrote:
> 
> Chris Gokey wrote:
> > Hi Conny,
> >
> > O.k.  I'm trying your suggestion of using <Link> and creating an template.  So for this
> > XML file:
> >
> > <Book>
> >    <Title>Master Xalan the XSLT processor</Title>
> >    <Summary>
> >      Xalan is an XSLT processor for transforming XML documents into HTML, text, or other
> >      XML document types. Xalan-Java version 1.2.D01 represents a complete and robust
> >      reference implementation of the W3C Recommendations for XSL Transformations XSLT)
> >      and the XML Path Language (XPath).  See <Link>http://xml.apache.org/xalan</Link> for
> >      more details.
> >    </Summary>
> > </Book>
> >
> > I'm new to XSL so some help in getting my template working would be very appreciated.
> > I created two templates: Link and Summary.
> >
> > <xsl:template match="Link">
> > <a>
> > <xsl:attribute name="href">
> > <xsl:value-of select="."/>
> > </xsl:attribute>
> > <xsl:value-of select="."/>
> > </a>
> > </xsl:template>
> >
> > <xsl:template match="Summary">
> > <pre>
> > <xsl:apply-templates select="Link"/>
> > <xsl:value-of select="."/>
> > </pre>
> > </xsl:template>
> >
> > This solution is obviously not correct because it applies the Link template first, then
> > prints ALL the summary information after that.  What I want is to apply the link templates
> > inside the output of the Summary template?  How can this be done?
> >
> > Thanks,
> > Chris
> 
> As I can see your <Link> template is correct. The summary could look like this:
> <xsl:template match="Summary">
>   <pre>
>     <xsl:apply-templates/>
>   </pre>
> </xsl:template>
> 
> That automatically calls templates for all text and element children of the
> 'Summary' element. (There is a default template for text which simply copies the
> text.)
> 
> ________________
> Conny Krappatsch
> SMB GmbH
> mailto:conny@smb-tec.com
> http://www.smb-tec.com
> 
> 

-- 
Christopher D. Gokey, Raytheon ITSS, NASA/GCMD
18 Martin Road, Shelburne Falls, MA  01370
Phone: Voice (413) 625-8129 / FAX 208-248-9055
cgokey@gcmd.nasa.gov / http://gcmd.nasa.gov

Re: can xalan hypertext link urls in xml tags?

Posted by Conny Krappatsch <co...@smb-tec.com>.
Chris Gokey wrote:
> Hi Conny,
> 
> O.k.  I'm trying your suggestion of using <Link> and creating an template.  So for this
> XML file:
> 
> <Book>
>    <Title>Master Xalan the XSLT processor</Title>
>    <Summary>
>      Xalan is an XSLT processor for transforming XML documents into HTML, text, or other
>      XML document types. Xalan-Java version 1.2.D01 represents a complete and robust
>      reference implementation of the W3C Recommendations for XSL Transformations XSLT)
>      and the XML Path Language (XPath).  See <Link>http://xml.apache.org/xalan</Link> for 
>      more details.
>    </Summary>
> </Book>
> 
> I'm new to XSL so some help in getting my template working would be very appreciated.
> I created two templates: Link and Summary. 
> 
> <xsl:template match="Link">
> <a>
> <xsl:attribute name="href">
> <xsl:value-of select="."/>
> </xsl:attribute>
> <xsl:value-of select="."/>
> </a>
> </xsl:template>
> 
> <xsl:template match="Summary">
> <pre>
> <xsl:apply-templates select="Link"/>
> <xsl:value-of select="."/>
> </pre>
> </xsl:template>
> 
> This solution is obviously not correct because it applies the Link template first, then
> prints ALL the summary information after that.  What I want is to apply the link templates
> inside the output of the Summary template?  How can this be done?
> 
> Thanks,
> Chris

As I can see your <Link> template is correct. The summary could look like this:
<xsl:template match="Summary">
  <pre>
    <xsl:apply-templates/>
  </pre>
</xsl:template>

That automatically calls templates for all text and element children of the
'Summary' element. (There is a default template for text which simply copies the
text.)

________________
Conny Krappatsch
SMB GmbH
mailto:conny@smb-tec.com
http://www.smb-tec.com


Re: can xalan hypertext link urls in xml tags?

Posted by Chris Gokey <cg...@gcmd.gsfc.nasa.gov>.
Hi Conny,

O.k.  I'm trying your suggestion of using <Link> and creating an template.  So for this
XML file:

<Book>
   <Title>Master Xalan the XSLT processor</Title>
   <Summary>
     Xalan is an XSLT processor for transforming XML documents into HTML, text, or other
     XML document types. Xalan-Java version 1.2.D01 represents a complete and robust
     reference implementation of the W3C Recommendations for XSL Transformations XSLT)
     and the XML Path Language (XPath).  See <Link>http://xml.apache.org/xalan</Link> for 
     more details.
   </Summary>
</Book>

I'm new to XSL so some help in getting my template working would be very appreciated.
I created two templates: Link and Summary. 

<xsl:template match="Link">
<a>
<xsl:attribute name="href">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
</xsl:template>

<xsl:template match="Summary">
<pre>
<xsl:apply-templates select="Link"/>
<xsl:value-of select="."/>
</pre>
</xsl:template>

This solution is obviously not correct because it applies the Link template first, then
prints ALL the summary information after that.  What I want is to apply the link templates
inside the output of the Summary template?  How can this be done?

Thanks,
Chris


Conny Krappatsch wrote:
> 
> Chris Gokey wrote:
> > Hi everyone,
> >
> > Given an XML file like this:
> >
> > <Book>
> >    <Title>Master Xalan the XSLT processor</Title>
> >    <Summary>
> >      Xalan is an XSLT processor for transforming XML documents into HTML, text, or other
> >      XML document types. Xalan-Java version 1.2.D01 represents a complete and robust
> >      reference implementation of the W3C Recommendations for XSL Transformations XSLT)
> >      and the XML Path Language (XPath).  See http://xml.apache.org/xalan for more
> >      details.
> >    </Summary>
> > </Book>
> >
> > Is there some mechanism in Xalan to hypertext link urls found inside the
> > element tags?  In the above example, I'd like to present the XML file in
> > HTML with the 'http://xml.apache.org/xalan' hypertext linked.
> >
> > Someone mentioned sometime back the possibility of using templates and
> > string functions, but it is not obvious to me how this can be done.
> > This would appear to be a common thing, some I'm hoping there is already
> > something built into Xalan.  Any suggestions, code, examples would be very
> > appreciated.
> 
> Hi Chris,
> 
> I could imagine a template that extracts strings starting with 'http://' and
> surrounds them with an <a> tag. Would require extensive usage of
> 'string-before()' and 'string-after()' functions and this may be someway slow.
> I would recommend marking up the links with a <link> tag or something similar
> and write a template for 'link'.
> 
> Conny
> 
> ________________________________________________________________
> Conny Krappatsch                     mailto:conny@smb-tec.com
> SMB GmbH                             http://www.smb-tec.com
> 
> 

-- 
Christopher D. Gokey, Raytheon ITSS, NASA/GCMD
18 Martin Road, Shelburne Falls, MA  01370
Phone: Voice (413) 625-8129 / FAX 208-248-9055
cgokey@gcmd.nasa.gov / http://gcmd.nasa.gov

Re: can xalan hypertext link urls in xml tags?

Posted by Conny Krappatsch <co...@smb-tec.com>.
Chris Gokey wrote:
> Hi everyone,
> 
> Given an XML file like this:
> 
> <Book>
>    <Title>Master Xalan the XSLT processor</Title>
>    <Summary>
>      Xalan is an XSLT processor for transforming XML documents into HTML, text, or other
>      XML document types. Xalan-Java version 1.2.D01 represents a complete and robust
>      reference implementation of the W3C Recommendations for XSL Transformations XSLT) 
>      and the XML Path Language (XPath).  See http://xml.apache.org/xalan for more
>      details.
>    </Summary>
> </Book>
> 
> Is there some mechanism in Xalan to hypertext link urls found inside the 
> element tags?  In the above example, I'd like to present the XML file in
> HTML with the 'http://xml.apache.org/xalan' hypertext linked.
> 
> Someone mentioned sometime back the possibility of using templates and
> string functions, but it is not obvious to me how this can be done.
> This would appear to be a common thing, some I'm hoping there is already
> something built into Xalan.  Any suggestions, code, examples would be very
> appreciated.

Hi Chris,

I could imagine a template that extracts strings starting with 'http://' and
surrounds them with an <a> tag. Would require extensive usage of
'string-before()' and 'string-after()' functions and this may be someway slow.
I would recommend marking up the links with a <link> tag or something similar
and write a template for 'link'.

Conny



________________________________________________________________
Conny Krappatsch                     mailto:conny@smb-tec.com
SMB GmbH                             http://www.smb-tec.com