[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] how to assign part of an attributes value to another
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
|
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
|