GessWurker
asked on
Adjust xslt to copy unmanipulated content to new line
I'm using the xslt below to strip out file extensions. Now, I'd like to also copy the unstripped complete file name into another line so that the output includes both the file name without ext and the file name WITH the ext.:
<idoc:ItemName>filename</i doc:ItemNa me> [extension stripped]
<idoc:ItemFileName>filenam e.ext</ido c:ItemFile Name> [original file name, including extension]
Here's the transform (thanks to Gertone!):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:idoc="http://ns.inmagic.com/Presto/1.0/ContentConnector/DocumentParameters">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="idoc:ItemName[norma lize-space (.)]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:value-of select="replace( ., '\.[^\.]+$', '')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here's some test input:
<?xml version="1.0" standalone="yes"?>
<idoc:FileDescription xmlns:idoc="http://ns.inmagic.com/Presto/1.0/ContentConnector/DocumentParameters">
<idoc:ItemURL>xpcc:///Copy _of_NC_268 ea83b7f074 da296495c5 e1e82e035/ Chopped Strand/testing123.pdf</ido c:ItemURL>
<idoc:NativeURL>\\serverNa me\dbstore \Inmagic\d c\Source\A nalytical Testing Reports\Chopped Strand\testing123.pdf</ido c:NativeUR L>
<idoc:ConnectorRootPath>// serverName /dbstore/I nmagic/dc/ Source/Ana lytical Testing Reports</idoc:ConnectorRoo tPath>
<idoc:ItemRelativePath>Cho pped Strand</idoc:ItemRelativeP ath>
<idoc:ItemName>testing123. pdf</idoc: ItemName>
<idoc:UID>//serverName/dbs tore/Inmag ic/Documen t Capture/Source/Analytical Testing Reports/Chopped Strand/testing123.pdf</ido c:UID>
<idoc:MimeType>application /pdf</idoc :MimeType>
<idoc:Extension>.pdf</idoc :Extension >
<idoc:ContentLength>163212 </idoc:Con tentLength >
<idoc:CreationDate>10/8/20 14 5:46:08 PM</idoc:CreationDate>
<idoc:LastModificationDate >10/8/2014 4:26:22 PM</idoc:LastModificationD ate>
</idoc:FileDescription>
<idoc:ItemName>filename</i
<idoc:ItemFileName>filenam
Here's the transform (thanks to Gertone!):
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:idoc="http://ns.inmagic.com/Presto/1.0/ContentConnector/DocumentParameters">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="idoc:ItemName[norma
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:value-of select="replace( ., '\.[^\.]+$', '')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here's some test input:
<?xml version="1.0" standalone="yes"?>
<idoc:FileDescription xmlns:idoc="http://ns.inmagic.com/Presto/1.0/ContentConnector/DocumentParameters">
<idoc:ItemURL>xpcc:///Copy
<idoc:NativeURL>\\serverNa
<idoc:ConnectorRootPath>//
<idoc:ItemRelativePath>Cho
<idoc:ItemName>testing123.
<idoc:UID>//serverName/dbs
<idoc:MimeType>application
<idoc:Extension>.pdf</idoc
<idoc:ContentLength>163212
<idoc:CreationDate>10/8/20
<idoc:LastModificationDate
</idoc:FileDescription>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
welcome
ASKER