Subject: [xsl] how to assign part of an attributes value to another attribute within the same element? From: "Tony Zanella" <tony.zanella@xxxxxxxxx> Date: Thu, 29 May 2008 19:51:32 -0400 |
Hello, With XSL Processor: Saxon 8B and XSL v. 2.0, here is my test case: <?xml version="1.0" encoding="UTF-8"?> <root> <ptr target="abc.07.7.1fm" n=""/> <ptr target="abc.07.7.6tm" n=""/> </root> Here is my stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="ptr[@target|@n]"> <xsl:element name="ptr"> <xsl:attribute name="target" select="@target"/> <xsl:attribute name="n" select="@target"/> </xsl:element> </xsl:template> </xsl:stylesheet> The output I get is: <?xml version="1.0" encoding="UTF-8"?><root> <ptr target="abc.07.7.1fm" n="abc.07.7.1fm"/> <ptr target="abc.07.7.6tm" n="abc.07.7.6tm"/> </root> This is not quite what I want, which is: <?xml version="1.0" encoding="UTF-8"?><root> <ptr target="abc.07.7.1fm" n="1"/> <ptr target="abc.07.7.6tm" n="6"/> </root> My thought is: if I could reach into the @target attribute value, and grab whatever numeral appears between the last period and tm or fm, assign it as the same ptr elements @n attribute value, that would be it. Theoretically, I can get the number I want by matching with the regex: abc\.07\.7\.([0-9]+)[tf]m and replacing with $1 (in Perl syntax, which my editor supports), and I have what I want to assign as the value of the @n attribute. I don't know if or how XSLT can help. If you know, I thank you in advance for sharing! Tony
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using parameter as regex , David Carlisle | Thread | RE: [xsl] how to assign part of an , Houghton,Andrew |
RE: [xsl] Using parameter as regex , Houghton,Andrew | Date | RE: [xsl] how to assign part of an , Houghton,Andrew |
Month |