Jump to content

MMM

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by MMM

  1. Thanks for your help. Sadly I can't get it working. 1. If I change the copy-of match from node() to text(), he stops copying all attributes.2. If I add the new template for adding the attribute he stops copying it. So the result is just:

    <InstanceHierarchy>        <InternalElement>		 </InternalElement>		 <InternalElement>		 </InternalElement></InstanceHierarchy>

    Do I make something wrong? Just say if you need example files to find the issue.

  2. Hi, I wanna add a little function to my XSLT File. I want to add an attribute with a constant value to an element if it is in a specific depth. My XSLT File merges 2 XML Files so far and looks like this:

    <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="CAEXFile"> <xsl:copy>   <xsl:apply-templates select="@* | node() | document('extra.xml')/CAEXFile/SystemUnitClassLib" /></xsl:copy></xsl:template> <xsl:template match="node() | @*"><xsl:copy-of select="." /></xsl:template> </xsl:stylesheet>

    Then I want to add the attribute:

    <xsl:template match="CAEXFile/InstanceHierarchy/InternalElement/InternalElement">  <xsl:attribute name="FurtherInformation">ConstantValue</xsl:attribute></xsl:template>

    But I'm confused where to put the code, because theres already a match "CAEXFile" to copy the whole tree. I'd be very glad if someone could help me with that.

  3. Ahh ok, one mistake. But with a XSLT file like this:

    <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="CAEXFile"><xsl:copy>   <xsl:apply-templates select="@* | node()" />   <xsl:apply-templates match="document('my2ndFile.xml')/CAEXFile/SystemUnitClassLib/node()" /></xsl:copy></xsl:template> <xsl:template match="node() | @*"><xsl:copy-of select="." /></xsl:template> </xsl:stylesheet>

    I receive the content of the main file doubled:

    <?xml version="1.0" encoding="utf-8"?><CAEXFile SchemaVersion="2.15" ...>		<InstanceHierarchy Name="Example">				...A lot of elements...		</InstanceHierarchy>		<InstanceHierarchy Name="Example">				...A lot of elements...		</InstanceHierarchy></CAEXFile>

  4. Hi, I'm new to XSLT and I got some problems with it. I want to merge 2 XML files. I want to copy everything from a main file and a specific element with its childs from a second file into the main root Element. Example: Main File:

    <?xml version="1.0" encoding="utf-8"?><CAEXFile SchemaVersion="2.15" ...>	<InstanceHierarchy Name="Example">		...A lot of elements...	</InstanceHierarchy></CAEXFile>

    2nd File:

    <CAEXFile ...>		<SystemUnitClassLib Name="Function">	...A lot of elements...	</SystemUnitClassLib></CAEXFile>

    Final File:

    <?xml version="1.0" encoding="utf-8"?><CAEXFile SchemaVersion="2.15" ...>	<InstanceHierarchy Name="Example">		...A lot of elements...	</InstanceHierarchy>	<SystemUnitClassLib Name="Function">	...A lot of elements...	</SystemUnitClassLib></CAEXFile>

    My try looks like this:

    <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="CAEXFile"><xsl:copy>   <xsl:apply-templates select="@* | node()" /></xsl:copy></xsl:template> <xsl:template match="node() | @*"><xsl:copy-of select="." /></xsl:template> </xsl:stylesheet>

    It copies the file correct, but how do I get the information out of the 2nd file? I tried something like this:

       <xsl:apply-templates	match="document('my2ndFile.xml')/SystemUnitClassLib/node()" />

    but without success. I found some Topics which had the same issue, but it couldn't help me. I'd be very thankful for any help.

×
×
  • Create New...