[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Transforming portions of content or values
Thanks for your help Rick ----- Original Message ----- From: "Rick Taylor" <taylor@xxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, May 07, 2003 9:11 PM Subject: Re: Transforming portions of content or values > You don't necessarily have to create variables. You could hard code the > company name and URL into the template. It just limits what you can do with > the template. You could also use parameters and then have the ability to > pass in different company names and urls. I am assuming that you don't > have the URL values within the source XML. > > <xsl:template match="experience"> > <xsl:value-of select="substring-before(.,'XYZ')"/> > <a href="www.xyz.com"> > <xsl:value-of select="'XYZ'"/> > </a> > <xsl:value-of select="substring-after(.,'XYZ')"/> > </xsl:template> > > In order to access the variable in any template, you must define it > globally (outside of a template). > > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:variable name="companyName" select="'XYZ'"> > or as a parameter > <xsl:param name="companyName" select="'XYZ'"> > ...... > </xsl:stylesheet> > > > At 08:33 PM 5/7/03 +0100, you wrote: > >Thanks Rick > > > >I understand all apart from the bit about variables, which I have not used > >before. > > > >Please would you clarify where in the stylesheet I put the variables? Within > >the parent template? > >Also, not sure why the URL needs to be in variables as well? > > > >Thanks > > > >Charles > > > >----- Original Message ----- > >From: "Rick Taylor" <taylor@xxxxxxxx> > >To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> > >Sent: Wednesday, May 07, 2003 4:58 PM > >Subject: Re: Transforming portions of content or values > > > > > > > > > > Charles, > > > > > > 1. There is not much difference in processing the XML to HTML in both of > > > the cases you provide. > > > You will probably need the company name and URL in global variables. > > > <xsl:variable name="companyName" select='XYZ'/> > > > <xsl:variable name="companyURL" select='www.xyz.com'/> > > > > > > Then in your template > > > You need to process the string 'Worked for XYZ Inc.' such that you > > > 1. get the substring before 'XYZ' > > > 2. process the XYZ > > > 3. get the substring after 'XYZ' > > > > > > <xsl:template match="experience"> > > > <xsl:value-of select="substring-before(.,$companyName)"/> > > > <a href="{$companyURL}"> > > > <xsl:value-of select="$companyName"/> > > > </a> > > > <xsl:value-of select="substring-after(.,$companyName)"/> > > > </xsl:template> > > > > > > 2. You can simply put one in. > > > <experience dates="1990 - 2000" company="Worked for XYZ Inc."> > > > > > > <xsl:template match="experience"> > > > <xsl:value-of select="@dates"/> > > > <xsl:text> </xsl:text> > > > <xsl:value-of select="@company"/> > > > </xsl:template> > > > > > > -rick > > > > > > At 09:08 AM 5/7/03 +0100, you wrote: > > > >Hi > > > > > > > >1. How do I transform a portion of text in an XML document so that I > >can > > > >nest it within hyperlink tags in an XSL stylesheet for HTML display, as > > > >follows? > > > > > > > >a. Content: > > > > > > > ><experience>Worked for XYZ Inc.</experience> > > > > > > > >transformed to HTML (where [XYZ] = hyperlink to www. xyz.com): > > > > > > > >Worked for [XYZ] Inc. > > > > > > > >b. Values: > > > > > > > ><experience dates="1990 - 2000" company="Worked for XYZ Inc."/> > > > > > > > >transformed to HTML (where [XYZ] = hyperlink to www. xyz.com): > > > > > > > >1990 - 2000 Worked for [XYZ] Inc. > > > > > > > >2. Which throws up another question: is it possible to insert a > > > >non-breaking space between text during the transformation e.g. between > >the > > > >2000 and the 'Worked' as above? > > > > > > > > > > > >Thanks > > > > > > > >Charles > > > > > > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > > > > Rick Taylor > > > XML Developer > > > PPDM Association > > > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > Rick Taylor > XML Developer > PPDM Association > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|