[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Accessing file properties
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@xxxxxxxxxxx -----Original Message----- From: Sean Tiley [mailto:sean.tiley@xxxxxxxxx] Sent: Saturday, January 26, 2008 9:56 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: 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
|
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
|