How to create xsl file

Hello experts,

i have two xml files. First config.xml file looks like:
<?xml version="1.0"?>
<project>
  <counties>
    <county dist_id="2">
      <id>1</id>
      <short_name>county short name</short_name>
      <name>county name</name>
      <relative_value></relative_value>
      <interval></interval>
      <color>some hexadecimal color value</color>
    </county>
.
.
other county elements

  </counties>
</project>

map.xml file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<map>
  <counties>
    <county>
      <id>1</id>
      <d>M 70.5977,253.427 L 70.0034,255.667........(coordinates)</d>
.
.
.
other d elements
    </county>
 </counties>
</map>

And map.xsl file:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:template match="map">
<svg width="800px" height="500px" xmlns="http://www.w3.org/2000/svg">
<g id="county">
<xsl:for-each select="counties/county">
      <xsl:element name="path">
            <xsl:attribute name="id">
                  <xsl:value-of select="id" />
            </xsl:attribute>
            <xsl:attribute name="d">
                  <xsl:value-of select="d" />
            </xsl:attribute>
            <xsl:attribute name="fill">#ffffff
            </xsl:attribute>
            <xsl:attribute name="stroke">#00B7EB
            </xsl:attribute>
            <xsl:attribute name="stroke-width">1.0
            </xsl:attribute>
            <xsl:attribute name="display">inline
            </xsl:attribute>
      </xsl:element>
</xsl:for-each>
</g>
</svg>
</xsl:template>
</xsl:transform>

I've created simple map.xsl file witch transform map.xml file to svg file. Like in my previous questions i'm not sure how to
copy color element text value from config.xml file to <xsl:attribute name="fill">#ffffff</xsl:attribute> element in map.xsl file in this for-each loop. When the color in config.xml is not defined  i want to let <xsl:attribute name="fill">#ffffff</xsl:attribute> element in white color like in example.


Please help me!
drahosAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
Try this
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
    <xsl:variable name="config" select="document('config.xml')//counties"></xsl:variable>
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
    <xsl:template match="map">
        
        <svg width="800px" height="500px" xmlns="http://www.w3.org/2000/svg">
            <g id="county">
                <xsl:for-each select="counties/county">
                    <xsl:variable name="this-id" select="id"/>
                    <xsl:element name="path">
                        <xsl:attribute name="id">
                            <xsl:value-of select="id" />
                        </xsl:attribute>
                        <xsl:attribute name="d">
                            <xsl:value-of select="d" />
                        </xsl:attribute>
                        <xsl:attribute name="fill">
                            <xsl:choose>
                                <xsl:when test="$config//county[id = $this-id]/color[normalize-space(.)]">
                                    <xsl:value-of select="$config//county[id = $this-id]/color"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:text>#ffffff</xsl:text>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="stroke">#00B7EB</xsl:attribute>
                        <xsl:attribute name="stroke-width">1.0</xsl:attribute>
                        <xsl:attribute name="display">inline</xsl:attribute>
                    </xsl:element>
                </xsl:for-each>
            </g>
        </svg>
    </xsl:template>
</xsl:transform>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drahosAuthor Commented:
Thanks a lot for a such helping solutions!
0
Gertone (Geert Bormans)Information ArchitectCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.