Jump to content

alpman

Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by alpman

  1. I'm trying to transform a SVG-file into another XML-file using XSLT and the C# class XslCompiledTransform. This is my SVG

    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg"	 xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events"	 version="1.1" baseProfile="full"	 width="800mm" height="600mm"><rect x="10" y="10" width="90" height="40" /></svg>

    This is my C#-Code

    static void Main(string[] args)		{			string xmlSource = args[0];			string xmlOutput = args[1];			string xsltFile = args[2]; 			// if xslt or soure contains a DTD:			XmlReaderSettings xmlReadSet = new XmlReaderSettings();			xmlReadSet.DtdProcessing = DtdProcessing.Parse;			xmlReadSet.ValidationType = ValidationType.Schema;			XslCompiledTransform xslt = new XslCompiledTransform(); 			//			XmlWriterSettings xmlWriteSet = new XmlWriterSettings();			xmlWriteSet.ConformanceLevel = ConformanceLevel.Auto; 			//			xslt.Load(xsltFile);			xslt.Transform(XmlReader.Create(xmlSource, xmlReadSet), XmlWriter.Create(xmlOutput, xmlWriteSet)); 		}

    And this is my XSLT

    <?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"	xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">	<xsl:output method="xml" version="1.0" indent="yes" encoding="utf-8" omit-xml-declaration="no"/> 	<xsl:template match="/">	  <xsl:element name="Redlining">		<xsl:attribute name="hash">???</xsl:attribute>		<xsl:attribute name="version">4.1</xsl:attribute> 		<xsl:element name="BoundingBox">		  <xsl:attribute name="xMin">???</xsl:attribute>		  <xsl:attribute name="yMin">???</xsl:attribute>		  <xsl:attribute name="xMax">???</xsl:attribute>		  <xsl:attribute name="yMax">???</xsl:attribute>		</xsl:element> 		<xsl:element name="GeometryHolder" />		<xsl:apply-templates select="rect"/>	  </xsl:element>	</xsl:template>   <xsl:template match="rect">	<xsl:element name="RectangleHolder">	  <xsl:element name="Sector">		<xsl:attribute name="type">sector</xsl:attribute>		<xsl:element name="Coordinate">		  <xsl:attribute name="x">			<xsl:value-of select="@x + @width"/>		  </xsl:attribute>				</xsl:element>	  </xsl:element>	</xsl:element>  </xsl:template></xsl:stylesheet>

    And this is what I get

    <Redlining hash="???" version="4.1"><BoundingBox xMin="???" yMin="???" xMax="???" yMax="???" /><GeometryHolder /></Redlining>

    As you can see the template "rect" is omitted. I got the advice to use this

    ...	  <xsl:apply-templates select=".//*[local-name()='rect']"/>	  ...    ...   <xsl:template match="*[local-name()='rect']">   ...

    Then I get what I want. But I don't understand what is wrong with my attempt since it seems that all the tutorials do it like my attempt. Or am I missing something? Thanks for reading, Stefan

×
×
  • Create New...