I have an XSLT that have several variable names such as pathFile, nameFile, fullPath.
Here is my input XML:
<?xml version="1.0" encoding="utf-8"?>
<DOCUMENT>
<EXTERNALFILES />
<OCRTEXTFILES />
<DOCUMENTINDEX Name="val1">val1</DOCUMENTINDEX>
<DOCUMENTINDEX Name="val2">val2</DOCUMENTINDEX>
<INSTANCEVALUE Name="InstanceID">instancevalue</KOFAXVALUE>
<PATHFILE Sequence="17">C:\myfolder\</TEXTCONSTANT>
</DOCUMENT>
I receive from an XML values as PATHFILE (with value "C:\myfolder\") and INSTANCEVALUE (with value "instancevalue") My objective is to concatenate pathFile and nameFile and to return a full path in the XML generated.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"
indent="yes" omit-xml-declaration="no" encoding="UTF-8" />
<xsl:template match="/">
<ImportDocument DocType="I"
xmlns="http://KOFAX_ERT/KOFAX_SAP_DocumentSchema.xsd">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="./DOCUMENTINDEX">
<DOCUMENTINDEX Name="{@Name}">
<xsl:value-of select="text()"/>
</DOCUMENTINDEX>
</xsl:for-each>
<xsl:variable name="pathFile" select="substring-before(./PATHFILE[@Sequence='17'],'.')"/>
<xsl:variable name="nameFile" select="substring-before(./INSTANCEVALUE[@Name='InstanceID'],'.')"/>
<xsl:variable name="fullPath" select="concat($pathFile,$nameFile)"/>
<Attachments>
<Attachment>
<FullPath>
<xsl:value-of select="concat($fullPath,'_signed.pdf')"/>
</FullPath>
</Attachment>
</Attachments>
</xsl:for-each>
</ImportDocument>
</xsl:template>
</xsl:stylesheet>
I would expect to have this result:
<DOCUMENTINDEX Name="val1">val1</DOCUMENTINDEX>
<DOCUMENTINDEX Name="val2">val2</DOCUMENTINDEX>
<Attachments>
<Attachment>
<FullPath>C:\myfolder\instancevalue_signed.pdf</FullPath>
</Attachment>
</Attachments>
Unfortunatelly it's not returning the expected ouput. Result I obtain is the following:
<DOCUMENTINDEX Name="val1">val1</DOCUMENTINDEX>
<DOCUMENTINDEX Name="val2">val2</DOCUMENTINDEX>
<Attachments>
<Attachment>
<FullPath>_signed.pdf</FullPath>
</Attachment>
</Attachments>
I finally solved my issue. I was using a collaborator code.
<Attachments>
<Attachment>
<xsl:variable name="pathFile" select="PATHFILE[@Sequence='17']"/>
<xsl:variable name="extension" select="PATHFILE[@Sequence='19']"/>
<xsl:variable name="nameFile" select="INSTANCEVALUE[@Name='InstanceID']"/>
<FullPath>
<xsl:value-of select="concat($pathFile, $nameFile, $extension)"/>
</FullPath>
</Attachment>
</Attachments>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.