[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

Subject: 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
 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.