Portia and Shylock both attend to the letter of the law.
This shared value is most obviously on display in the courtroom scene, when Shylock refuses to allow Antonio to repay him three times the amount of the original loan, instead demanding that Antonio stick to the literal terms of the contract. We know that this doesn't stem from his greed, because Shylock doesn't gain any material wealth or success by taking the "pound of flesh" guaranteed by the contract--in fact, by turning down the offer of triple repayment, he's losing money. Instead, he seems motivated by a combination of revenge against Antonio's earlier insults to him and to his fellow Jews (when they are first together on stage, Shylock says Antonio kicked him like a stray dog and called him a "misbeliever, cut-throat, dog / And spit upon my Jewish gaberdine", I.iii) and his devotion to the literal terms of the written contract. While medieval and Renaissance Christians contrasted what they saw as a Jewish over-strict adherence to justice and law with a Christian emphasis on mercy, it turns out that Portia has her own fair share of literal-mindedness.
In the courtroom scene, Portia outdoes even Shylock in her commitment to literal interpretation of the contract, and in so doing, finds a quibble that lets her release Antonio from the pound of flesh penalty. Her ability to literally interpret contracts and laws wins out over the Jewish Shylock's.
While this literalness is framed in The Merchant of Venice as a means to an end, rather than an aspect of Portia's personality, the courtroom scene isn't the only time that she chooses to adhere to contracts and laws. In fact, we see her hold to the terms of her father's will long before she hears anything about Shylock. Her father's will stipulates that her suitors must guess which of three caskets her portrait lies in, and she can only (and must) marry whoever guesses correctly (see II.vii.11-12 and II.vii.61-2). When it occurs to her that she could cheat a little and encourage her favored suitor to choose the right casket--in other words, to follow the form but not the letter of her father's will--she refuses.
I could teach you
How to choose right, but then I am forsworn;
So will I never be: so may you miss me;
But if you do, you'll make me wish a sin,
That I had been forsworn. (III.ii.10-14)
If he guesses wrong, she says, she will wish that she had cheated the will. Still, she refuses to do it, preferring to keep her faith in the outcome of exactly following the rules set forth in her father's will. She trusts the will as a test of Bassanio: "If you do love me, you will find me out" (III.ii.41), she says, meaning that if he's sincere, Bassanio will find her portrait in the casket he chooses. Like Shylock, then, Portia takes the literal sense of legal documents seriously enough to bet her happiness (and in the courtoom scene, Antonio's life) on them.
See recent notes and place your Q in the search MV box(above right) or browse, etc. Another issue is that we learn in Act 1, scene 2 that Portia's father has died. It is implied that Shylock's wife has also died(3.1). So, each seems to be dealing with a death in the family.