Creating two different outputs for the same XSL file?

This is my XML file, and if I run the XSLt file, I will get the same result in the same order as in Eclipse XSL Transformation. Even if you add a new record to my XML file and run the XSL file, it <xsl:value-of select="generate-id(.)"/>will create a unique identifier for the new record.

<?xml version="1.0" encoding="UTF-8"?>
<CONTACTS>

<CONTACT>
<Customer-ID>N65539</Customer-ID>
<FirstName>Ben</FirstName>
<LastName>Foden</LastName>
<email></email>
<address></address>
<state>AZ</state>
<country>US</country>
</CONTACT>

<CONTACT>
<Customer-ID>N65539</Customer-ID>
<FirstName>Nimal</FirstName>
<LastName>Anup</LastName>
<email>nimal.anup@gmail.com</email>
<address></address>
<state>TN</state>
<country>IN</country>
</CONTACT>


<CONTACTS>

This is my updated XSLT file:

  <?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />

<!--Identity template to copy content forward-->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
</xsl:template>

    <xsl:template match="CONTACT">
<xsl:copy>
    <Customer-ID>
    <xsl:apply-templates select="node()" mode="generate-id"/>
    </Customer-ID>

    <FirstName>
    <xsl:value-of select="FirstName"/> 
    </FirstName>

    <LastName>
    <xsl:value-of select="LastName"/> 
    </LastName>

    <email>
    <xsl:value-of select="email"/> 
    </email>

    <address>
    <xsl:value-of select="address"/> 
    </address>

    <state>
    <xsl:value-of select="state"/> 
    </state>

    <country>
    <xsl:value-of select="country"/> 
    </country>

</xsl:copy>
    </xsl:template>

    <xsl:template match="node()" mode="generate-id">
    <xsl:text>N</xsl:text>
    <xsl:number level="single" count="node()" format="100"/>        
    </xsl:template>

</xsl:stylesheet>

Then I used the same XSLT file for the XSLT processor function in XUL, and I get an identifier and output of a different type. It continues to generate a new identifier for the old record and for the new record. If I add a new entry to the XML file.

How to create a new identifier only for a new record? and how can I have the same XML template of my input file in the XML output file.

This is the result I get:

<?xml version="1.0" encoding="UTF-8"?>
<CONTACTS>

<CONTACT><Customer-ID>id0x03e4a620</Customer-ID><FirstName>Ben</FirstName><LastName>Foden</LastName><email></email><address></address><state>AZ</state><country>US</country></CONTACT>

<CONTACT><Customer-ID>id0x03e4ad80</Customer-ID><FirstName>Nimal</FirstName><LastName>Anup</LastName><email>nimal.anup@gmail.com</email><address></address><state>TN</state><country>IN</country></CONTACT>

<CONTACTS>

Javascript XSLT: script XML . , XML .

function process()
{

var src = readFile("c:\\idgenerator.xsl");
var parsed = (new DOMParser()).parseFromString(src, "text/xml");
var stylesheet = parsed.documentElement;

var processor = new XSLTProcessor();
processor.importStylesheet(stylesheet );

objXMLDoc = processor.transformToDocument(objXMLDoc);

var serializer = new XMLSerializer();
var prettyString = serializer.serializeToString(objXMLDoc);

saveFile(prettyString, "C:\\mercredi.xml");

} 

.

+2
3

, XSLT- Eclipse. , , . Xalan Saxon. Mozilla/XUL Transformiix, , . - , . , XSLT-.

generate-id() , ; " - ASCII ".

, XSLT-under-XUL , Eclipse, .

1) XUL XSLT-, Eclipse. , .

2) .

, , Eclipse, XSLT-, .

, ( ), :

<xsl:template match="node()" mode="generate-id">
    <xsl:text>N</xsl:text>
    <xsl:number level="any" count="node()" format="00001"/>        
</xsl:template>

, + ,

<xsl:template match="node()" mode="generate-id">
   <xsl:value-of select="concat(FirstName, LastName)" />
</xsl:template>
+2

generate-id() , XSLT-, , .

+3

generate-id() , , , generate-id(), ...

<xsl:if test="./Customer-Id=''"> <!-- if the new contact comes with this empty -->
    <Customer-ID>
        <xsl:value-of select="generate-id(.)"/> 
    </Customer-ID>
<xsl:if>
<xsl:if test="not(./Customer-Id='')"> <!-- if the contact comes with Customer-Id -->
    <Customer-ID>
        <xsl:value-of select="Customer-Id"/> 
    </Customer-ID>
<xsl:if>
0

All Articles