xsl-list
[Top] [All Lists]

RE: [xsl] Accessing file properties

2008-01-26 20:48:16
Hi, Sean:

  Sadly, XSLT has no search and replace functions of arguments like Perl. If 
you want, you can write a little program in Perl, and tell it to search for 
your <file name="WORD_DOC_NAME"> string, and use a substring function to 
replace it with your intended file name.

  What you can do, if you do have a lot of WORD_DOC_NAME that you want to 
replace at once, you can use this little recipe:

fn:replace(string,pattern,replace)
Returns a string that is created by replacing the given pattern with the 
replace argument

Example: replace("Bella Italia", "l", "*")
Result: 'Be**a Ita*ia'
Example: replace("Bella Italia", "l", "")
Result: 'Bea Itaia'

This is taken from the W3 Schools site, or you can look at 
http://www.xsltfunctions.com/xsl/fn_replace.html
There are also some discussion on replace() on Michael Kay's XPath.

<xsl:template match="file">
<xsl:choose>
<xsl:when test="contains(@name,'WORD_FILE_DOC')">
<xsl:value-of select="replace(@name,'FILE','NEW')">
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=".">
</xsl:otherwise>
</xsl:template>

Good luck!

 ======================================================
 Alice Wei
 MIS 2008
 School of Library and Information Science
 Indiana University Bloomington
 ajwei(_at_)indiana(_dot_)edu


-----Original Message-----
From: Sean Tiley [mailto:sean(_dot_)tiley(_at_)gmail(_dot_)com]
Sent: Saturday, January 26, 2008 9:56 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Accessing file properties

Hi Alice,
Yes, I want to output the document name in my resulting xml file which
looks like the following

<testresults>
    <file name="WORD_DOC_NAME">
        <testruns>
            <testrun>
                <test case="TC-01" result="FAIL" date="2008-01-25" bugid="123"/>
                <test case="TC-02" result="FAIL" date="2008-01-25" bugid="456"/>
                <test case="TC-03" result="FAIL" date="2008-01-25" bugid="789"/>
                <test case="TC-04" result="PASS" date="2008-01-25"/>
            </testrun>
            <testrun>
                <test case="TC-01" result="PASS" date="2008-01-26"/>
                <test case="TC-02" result="PASS" date="2008-01-26"/>
                <test case="TC-03" result="FAIL" date="2008-01-26" bugid="790"/>
                <test case="TC-04" result="PASS" date="2008-01-26"/>
                <test case="TC-05" result="PASS" date="2008-01-26"/>
                <test case="TC-06" result="FAIL" date="2008-01-26" bugid="791"/>
            </testrun>
        </testruns>
    </file>
    <file/>
    ...
</testresults>


I wish to replace "WORD_DOC_NAME" with the file name

Thanks
Sean

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>