|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello
I am trying to transform an XML document (the source is from Lotus Notes so it is actually "DXL"). I have a particular xml field/entry that contains URLs. I want to use my existing XSLT to transform SOME of the URLS (based on a pattern) into different URLs. Example: In the source document there is this URL: http://someserver.company.com/folder/database.nsf/idnum/20040293939393or http://someserver.company.com/folder/database.nsf/idnum/20040293939393?open&someparmemter=somevalue All the URLS that I want to transform are basically the same structure but what I need to do is to extract the value after the "/idnum/" and ending with a termination of the URL or when the "?" appears and then REPLACE the URL with a new one. The links can appear just as text or they can actual 'links' in the field. Here is a sample XSLT statement within an entire XSLT: <Solution><xsl:choose><xsl:when test="//dxl:item[@name='Solution']/dxl:richtext"><xsl:copy-of select="//dxl:item[@name='Solution']/dxl:richtext"/></xsl:when><xsl:otherwise><richtext xmlns="http://www.lotus.com/dxl"/></xsl:otherwise></xsl:choose></Solution> Is there a way within this statement to write a transformation that will search through this field, locate the proper pattern and extract out the "number" I want so I could then construct a new URL: http://newserver.somecompany.com/docx/20040293939393.jsp a) is this possible? b) how do you do it? Note - my transformation currently works perfectly so please go on the assumption that namespaces and other items in the XSLT are working. Thanks Terry |
|
#2
|
||||
|
||||
|
It is possible, I am working on it now.
|
|
#3
|
||||
|
||||
|
This is the XSL template used to extract a portion of a link:
Code:
<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:for-each select="rootNode/link"> <xsl:call-template name="extractNumberFromLink"> <xsl:with-param name="link" select="."/> </xsl:call-template> </xsl:for-each> </xsl:template> <xsl:template name="extractNumberFromLink"> <xsl:param name="link"/> <xsl:variable name="COMES_AFTER" select="'/idnum/'"/> <xsl:variable name="COMES_BEFORE" select="'?'"/> <xsl:variable name="result" select="substring-after($link, $COMES_AFTER)"/> <xsl:choose> <xsl:when test="contains($result, $COMES_BEFORE)"> <xsl:value-of select="substring-before($result, $COMES_BEFORE)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$result"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Test XML: Code:
<?xml version="1.0"?> <rootNode> <link>http://someserver.company.com/folder/database.nsf/idnum/20040293939393or</link> <link>http://someserver.company.com/folder/database.nsf/idnum/20040293939393?open&someparmemter=somevalue</link> </rootNode> You should probably read the spec or read about all of the standard functions of XSL before continue using it. http://www.w3c.org |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSLT Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|