using "unparsed-text" function with variable values
HI There
i am converting an xml file to another xml file with a different format. in my older xml file i have a tag which contains a file name. this file is a txt file, whose contents i would like to show as the contents of an attribute in my new xml.
here's a quick example: Old xml: <FILE>title.txt</FILE> New xml: <TAG attr1="sometext" attr2="content of title.txt"/>
i am using xsl:stylesheet version="2.0" , and trying to work with the function unparsed-text as follows: <xsl:attribute name="attr2" select="fn:unparsed-text('title.txt', 'utf-8')"/> the above statement works fine, but as soon as i try using a variable instead of an absolute value for the file name, i get "Error in XPath 2.0 expression". here's my code: <xsl:variable name="v1" select="FILE"/> <xsl:variable name="v1" select="unparsed-text('$v1', 'utf-8')"/>
any idea why this is not working, and how i might solve this problem?
Jyske Bank er rykket ind i Glaskuben på Kalvebod Brygge, et markant byggeri i hjertet af København. Knap 1.000 arbejder her, heraf 200 i IT, med nye rammer for samarbejde, innovation og udvikling.
But is it relative to some http:URL, or to a OS file name? Mye guess is that this is more likely to work with HTTP: than with file:.
Synes godt om
Slettet bruger
27. oktober 2005 - 11:26#2
If it's not a typo (or redefinition is allowed in 2.0), the reason it's failing is because you cannot redefine a variable. Give the second variable another name (say, 'v2') AND you should probably try a slight variation of quoting when using variables/parameters:
my bad. i need to include the contents of the text file in an attribute. so after having assigned the contents of the file to a variable: <xsl:variable name="v1" select="FILE"/>, where file is the tag in the original xml that contains the path to the txt file then i want to assign the contents to an attribute in the second xml file: <xsl:attribute name="attr2" select="unparsed-text($v1)"/>
that's what's not working. whenever i try to insert the path itself: unparsed-text('title.txt'), it works fine.
Synes godt om
Slettet bruger
27. oktober 2005 - 14:02#5
Ah, OK...
If <FILE> is in another file, use the document() function, something like this:
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.